[Solved] Docker exec to send command to running process stdin

Hi,

I started container with java process and -d switch (detached). Now I want to send command to that running java process (as if I would run this container without -d interactively and print command manually). If I use

docker exec -it my_container set a=1

where “set a=1” is the command, than I get error:

rpc error: code = 2 desc = oci runtime error: exec failed: exec: “set”: executable file not found in $PATH

So I suppose that docker is trying to run this command not in the process in foreground but on the container os command line (bash?). So the question is how can I send commands to the process in the foreground inside running container?

The solution I came up with is to run docker container inside linux screen. I start container in detached screen session like this:

screen -AmdS my_app_screen docker run -it --name my-app myimage

and then I use this bash script to send “set a=1” command to the docker container stdin:

screen -p 0 -S my_app_screen -X eval "stuff 'set a=1'\015"
sleep 1;

And btw, Docker Remote API could be used to achieve this too, but it’s more suitable to use within you web apps.