github.com/eikeon/docker@v1.5.0-rc4/docs/sources/articles/host_integration.md (about) 1 page_title: Automatically Start Containers 2 page_description: How to generate scripts for upstart, systemd, etc. 3 page_keywords: systemd, upstart, supervisor, docker, documentation, host integration 4 5 # Automatically Start Containers 6 7 As of Docker 1.2, 8 [restart policies](/reference/commandline/cli/#restart-policies) are the 9 built-in Docker mechanism for restarting containers when they exit. If set, 10 restart policies will be used when the Docker daemon starts up, as typically 11 happens after a system boot. Restart policies will ensure that linked containers 12 are started in the correct order. 13 14 If restart policies don't suit your needs (i.e., you have non-Docker processes 15 that depend on Docker containers), you can use a process manager like 16 [upstart](http://upstart.ubuntu.com/), 17 [systemd](http://freedesktop.org/wiki/Software/systemd/) or 18 [supervisor](http://supervisord.org/) instead. 19 20 21 ## Using a Process Manager 22 23 Docker does not set any restart policies by default, but be aware that they will 24 conflict with most process managers. So don't set restart policies if you are 25 using a process manager. 26 27 *Note:* Prior to Docker 1.2, restarting of Docker containers had to be 28 explicitly disabled. Refer to the 29 [previous version](/v1.1/articles/host_integration/) of this article for the 30 details on how to do that. 31 32 When you have finished setting up your image and are happy with your 33 running container, you can then attach a process manager to manage it. 34 When you run `docker start -a`, Docker will automatically attach to the 35 running container, or start it if needed and forward all signals so that 36 the process manager can detect when a container stops and correctly 37 restart it. 38 39 Here are a few sample scripts for systemd and upstart to integrate with 40 Docker. 41 42 43 ## Examples 44 45 The examples below show configuration files for two popular process managers, 46 upstart and systemd. In these examples, we'll assume that we have already 47 created a container to run Redis with `--name=redis_server`. These files define 48 a new service that will be started after the docker daemon service has started. 49 50 51 ### upstart 52 53 description "Redis container" 54 author "Me" 55 start on filesystem and started docker 56 stop on runlevel [!2345] 57 respawn 58 script 59 /usr/bin/docker start -a redis_server 60 end script 61 62 63 ### systemd 64 65 [Unit] 66 Description=Redis container 67 Author=Me 68 After=docker.service 69 70 [Service] 71 Restart=always 72 ExecStart=/usr/bin/docker start -a redis_server 73 ExecStop=/usr/bin/docker stop -t 2 redis_server 74 75 [Install] 76 WantedBy=local.target