Docker Community Forums

Share and learn in the Docker community.

Interactive container with daemon process


(Ivan Leon Moresco Jacques) #1

Hello Docker Community!

I would like to know if it is possible to run a interactive container (bash shell, for example), also having a daemon process that starts when you build the container.

Basically, I’m using the ENTRYPOINT option in my Dockerfile and with this, trying to start a MySQL daemon (ENTRYPOINT [“service”, “mysql”, “start”]). I want to create an interactive container from this image: starting a Bash shell, but also, with the MySQL daemon running on the background.

Any help is much appreciated :slight_smile:!

Thank you guys!

(David Maze) #2

Almost certainly what you want to do is set up a normal non-interactive container, and use docker exec to get a shell in it. For instance,

docker run -d -p 3306:3306 --name mysql mysql:5.7
docker exec -it mysql bash

That is, the container “is” the database instance, and the shell is just a debugging convenience on the side.

Two tips:

  • You should only really use ENTRYPOINT to create a wrapper script that will go off and run the eventual CMD. Otherwise, debugging the container with things like docker run --rm -it myimage /bin/sh is really hard to do.
  • You shouldn’t try to use commands like service or systemctl that expect an init system to be running. Directly run the mysqld instead.

Looking at the stock MySQL image will probably be informative; it includes an ENTRYPOINT script that creates the initial database and then runs the database daemon, or whatever command got passed in.