As I hosted a WordPress site in docker containers and i want these containers to be started at boot time always, so need to done it manually.

  • which ubuntu version do you use?
    – Maythux
    Commented May 8, 2015 at 7:47
  • using ubuntu server 14.04 Commented May 8, 2015 at 8:01
  • This has been asked on ServerFault. Commented Feb 22, 2016 at 2:08
  • Crossposted. Please pick one site, not many, for posting things on.
    – Thomas Ward
    Commented Jan 19, 2017 at 20:12

4 Answers 4


It is a very common use case to add the restart policy on an existing container.

This could be done with the following command: docker update --restart {no,on-failure,unless-stopped,always} container_name

More details: Docker - Start containers automatically

  • 2
    This solved my problem perfectly! I had a container with my database, and wanted it to start when my Mac started. By specifying that its image was always restarted (unless stopped), this did the trick!
    – Colin
    Commented Aug 22, 2018 at 15:20
  • They don't mention update anywhere on that page, great trick! I went w/ systemd files, because I thought the only way was to delete and re-run with restart flag~! Commented Feb 18, 2020 at 4:10
  • A downside to using systemd is that if I use docker stop then systemd restarts it~! You have to use systemd stop to stop the container~! Commented Feb 18, 2020 at 4:13
  • doesn't wok on MacOS Error response from daemon: No such container: on-failure Commented Mar 17, 2020 at 7:22
  • @deathangel908 try with --restart=on-failure
    – Slim
    Commented May 1, 2020 at 15:38

Till now I don't think there is a way to do that normally. A tricky solution is to use restart policy

sudo docker run --restart=always -d your_image

This means whenever you shut down this will exit your container so as you start your host then this lead to restart the docker.

  • as i search about it there are some automation tools like chef but dont know how to use them Commented May 8, 2015 at 8:17
  • It still experimental for Ubuntu github.com/bflad/chef-docker/blob/master/README.md
    – Maythux
    Commented May 8, 2015 at 8:19
  • 2
    Why not use system possibilities for this? both upstart and systemd can deal with this perfectly
    – Reishin
    Commented Nov 18, 2015 at 0:13

As ubuntu 15 now supports systemd, sample for this manager:


Description=Some service

ExecStart=/usr/bin/docker start -a container_name
ExecStop=/usr/bin/docker stop -t 2 container_name


More available on docker site

P.S. Pretty cute config :)

  • A downside to using systemd is that if I use docker stop then systemd restarts it~! You have to use systemd stop to stop the container~! Commented Feb 18, 2020 at 4:14
  • @FreeSoftwareServers well, if you put something to be managed by something, then you should not manage it manually and let it be managed by that tool. Alternatively, you can edit the service file to instruct systemd to start the service only at booting sequence, i showed here the generic approach - details can be tuned further by any your needs.
    – Reishin
    Commented Feb 19, 2020 at 20:48
  • That might make a good edit Commented Feb 20, 2020 at 1:15
  • You might as well use supervisor if going this route. You want all control in Docker and not anywhere else, that's why you'd have used Docker in the first place.
    – chx101
    Commented Jan 4, 2021 at 7:44

What I did is to use Upstart files.

You can find some examples and other solutions in the Docker website.

Create a file such like that in /etc/init :

Description "My container"
start on filesystem and started docker
stop on runlevel [!2345]
   /usr/bin/docker start -a mycontainer
end script
pre-stop script
  /usr/bin/docker stop mycontainer
end script

Note, as from Docker 1.2, there are restart policies which may also help to automatically restart containers when the docker service is run (after boot for example).

Personnaly, I use puppet to provision my workstation and use this Docker module to automatically create the startup scripts which are more complete (start, stop, restart, clean options...)


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .