Docker Community Forums

Share and learn in the Docker community.

External communications with program inside a Docker container


(Arthurgoldberg) #1

Hello

We’re building a large system which we will distribute in a Docker container. To make the system easy to use, we plan to create a portable, lightweight program that uses Python and a small number of standard Python packages (including docker) and then manages the creation of our Docker container and execution of code inside the container. (Computational expert users would use a terminal command line in the container, but other users will just use the lightweight program.) The container will have all our software and all the software our code uses, some credentials, and some customization for the person using it.

I’ll call the lightweight program ‘custom_docker_mgt’ and the container ‘custom_container’.

custom_docker_mgt and custom_container can use docker --volume to share some directories.

custom_docker_mgt will be a command line interface with sub-commands, like git and a lot of bio-informatic programs. (We can layer on a GUI later.)
custom_container will have a dispatcher program (called custom_dispatcher) that accepts commands from custom_docker_mgt. custom_dispatcher will de-multiplexes the commands and issue sub-commands to the right packages in custom_container. custom_dispatcher will report errors it identifies in the commands it receives. stdout and stderr in custom_container will be output directly to an attached terminal in which custom_docker_mgt runs.

The obvious way to communicate between custom_docker_mgt and custom_dispatcher is via docker exec and a shell running in custom_container:

docker exec custom_container sh -c 'custom_dispatcher <rest of arguments>'

The drawback of this approach is the nightmare of quoting shell arguments. Perhaps a package exists that completely handles shell argument quoting, but I’m not aware of one.

Another way to communicate between custom_docker_mgt and custom_dispatcher would be to run custom_dispatcher as a server and pass commands over a clean TCP connection, which has no quoting problems. But that approach would make both custom_docker_mgt and custom_dispatcher somewhat more complex.

What approach do you recommend? Does native Docker support for this type of communications exist? I think it might be generally useful.

Thanks
Arthur