简体   繁体   中英

Docker start a process on startup in the background and still use the container interactively

I use a Docker container for doing scientific calculations. All my libraries are installed inside the docker container. In addition, I got ParaView installed in order to do live visualizations.
For my simulation pipeline, I need to keep a ParaView server running inside the container while working with my bash shell inside it. A working solution for me is to use tmux as a terminal multiplexer, start the pvserver in one terminal session and use the other to do my simulation stuff.
However, this is very inconvenient and I would like to start the ParaView server on each start of the container automatically in the background. For this purpose, I tried to modify the ENTRYPOINT as:

ENTRYPOINT pvserver && /bin/bash

This works but does not allow me to use the shell, nor can I move the pvserver process in the background. Therefore it does not solve the issue of not using tmux for me. Then I tried to move the pvserver command into a CMD block, but that only starts and directly ends the process. So how can I start the server in the background while still being able to use the shell as usual when starting the container with the -it flag.

Generally, I read a couple of questions regarding this topic already, but most of the questions (or the docker documentation itself) focus either running just one process in the background and using bash as main process to not terminate the container, or they focus on running multiple predefined processes (not the shell) simultaneously like in the documentation.

The reason why the documentation you found says to do it that way, is because that's how containers are intended to be used. One process per container.

You can try publishing a port on your service then using your local shell to interact with the container over the published port.

Or you can try splitting the shell and the server into two containers, and exec-ing into the shell container to then access the server container, but this is a bit convoluted and unneccessary imo.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM