Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get docker container to read from stdin?

Tags:

docker

I have a script that I want to use to use Sigil (based on Go's template engine) to populate template files

I'm using a dockerized sigil for this via:

docker run -v ${TEMPLATE_DIR}:/tmp/sigil mikegrass/gliderlabs_sigil-docker/sigil -f prometheus-configmap.yaml -p API_SERVER=$api_server_url > $TEMP_FILE

This seems a bit clunky with having to map a volume, so I'd rather use STDIN to pass in the file....

So what I'd like is

cat ./prometheus-configmap.yaml | docker run mikegrass/gliderlabs_sigil-docker -p API_SERVER=$api_server_url > $TEMP_FILE

Unfortunately this doesn't work, I get no output.

Googling around I see possible solutions but haven't gotten any to work...

like image 459
phil swenson Avatar asked Jun 07 '17 19:06

phil swenson


People also ask

What is stdin and stdout in docker?

In general they are same as what you have mentioned and read in reference links for python. streams for receiving or reading input (stdin) and printing output (stdout). Example input from the keyboard or printing output to unix terminal. one reference here.

What happens when you press Ctrl P Q inside the container?

You have to use two combinations, one after the other: ctrl+p followed by ctrl+q. You turn interactive mode to daemon mode, which keeps the container running but frees up your terminal. You can attach to it later using docker attach, if you need to interact with the container more.

How do you interact with a docker container?

The docker exec and docker attach commands allow you to connect to a running container. To get an interactive shell to a container, use the exec command to start a new shell session. The attach command attaches your terminal to a running container.

How do I connect to a docker container shell?

To connect to a container using plain docker commands, you can use docker exec and docker attach . docker exec is a lot more popular because you can run a new command that allows you to spawn a new shell. You can check processes, files and operate like in your local environment.


1 Answers

You need to run the container in interactive mode with --interactive or -i:

cat ./prometheus-configmap.yaml | docker run -i mikegrass/gliderlabs_sigil-docker -p API_SERVER=$api_server_url > $TEMP_FILE
like image 95
Andy Shinn Avatar answered Sep 28 '22 06:09

Andy Shinn