First, there is a problem in your Dockerfile
:
RUN service mysql restart && /tmp/setup.sh
Docker images do not save running processes. Therefore, your RUN
command executes only during docker build
phase and stops after the build is completed. Instead, you need to specify the command when the container is started using the CMD
or ENTRYPOINT
commands like below:
CMD mysql start
Secondly, the docker container needs a process (last command) to keep running, otherwise the container will exit/stop. Therefore, the normal service mysql start
command cannot be used directly in the Dockerfile.
Solution
There are three typical ways to keep the process running:
This is often preferred when you have a single service running as it makes the outputted log accessible to docker.
This works only if there is a script like mysqld_safe
.
This is best if the command must perform a series of steps, again, /start.sh
should stay running.
Note
For the beginner using supervisord
is not recommended. Honestly, it is overkill. It is much better to use single service / single command for the container.
BTW: please check https://registry.hub.docker.com for existing mysql docker images for reference
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…