How can I ensure the Docker container starts and stays on the production server?
I would like to write a Bash script that will run on a production server. It will download the Docker image from the Docker Hub, launch it, and save the rendered container. Inside the container, I use Supervisor to keep the server and database running, and Supervisor will restart any process that dies inside the container.
But what about the container itself - are there any best practices / guidelines to ensure that the container starts after the host machine reboots and that the container is restarted if it crashes somehow? There is a --restart
flag that can be passed docker run
. So to ensure that the container starts and stays running, all that is needed is to add this line to /etc/rc.local
?
docker run -d --restart=always --name=container-name image-name command
Right? (And I don't need to use nohup
either &
.) Or are there some problems with this approach that I am missing, or something else that I am missing?
For example, do I not need to somehow guarantee that the docker service itself stays up and running? Can I believe he stays alive?
(A related question, but only about starting docker and not starting it on reboot: make sure the given docker container is running )
My host and OS container: Ubuntu 14.04.
source to share
With --restart = always you only need to do the docker start. Docker will then take care of the restart. So just run this command once:
docker run -d --restart=always --name=container-name image-name command
and docker will restart the container after the container process finishes and after reboot.
source to share