What is a good way to automatically start docker containers when the system boots up?
Is there a preferred way to do this on Ubuntu 14.04?
I've used supervisord
in the past to auto start web apps. But that doesn't feel like the right thing for Docker.
Apparently, the current method to auto-start Docker containers (from Docker 1.2) is to use restart policies. This will control how Docker should handle starting of the container upon startup and re-starting of the container when it exits. I've used the 'always' option so far, and can confirm that it makes Docker auto-start the container at system boot:
Documentation Excerpt
Docker has this page that explains how to do it with upstart and systemd. I agree that it doesn't seem like the right thing for Docker. Their solution is to run
docker start
, which assumes that you've already created your container. I would think that you'd either dodocker run --rm
in the upstart script (treating it like a brand new process and container from an image) or just let the docker daemon restart the containers itself on boot (as it will by default if you do nothing else). Upstart has the advantage of allowing easy start/stop of processes, but you get that with docker's start/stop too!I think it's weird to force the user to manually create a container (with all the correct port/volume bindings) before the upstart script will work.
Why not?
I use supervisord for this with great success.
Use what you know, use what works, use something that you can easily maintain and understand.