title: How to ensure a Docker container starts and stays running on a production server?
body: <p>I'd like to write a Bash script that one would run on a production server. It would download a Docker image from the Docker hub, start it and keep the resulting container running. Inside the container, I'm using <a href="http://supervisord.org/" rel="nofollow noreferrer">Supervisor</a> to keep a server and a database running, and Supervisor restarts any process that dies inside the container.</p>
  
  <p>But what about the container itself — are there any recommendations / best-practices about how to ensure that a container starts after the host machine has been rebooted, and that the container restarts if it crashes somehow? There is a <a href="https://docs.docker.com/reference/commandline/cli/#restart-policies" rel="nofollow noreferrer"><code>--restart</code> flag</a> that one can give to <code>docker run</code>. Therefore, to ensure a container starts and stays running, all that's needed is to add this line to <code>/etc/rc.local</code>?</p>
  
  <pre><code>docker run -d --restart=always --name=container-name image-name command
  </code></pre>
  
  <p>Right? (And I don't need to use <code>nohup</code> or any <code>&amp;</code>.) Or is there some problem with this approach that I'm overlooking, or something else that I'm missing?</p>
  
  <p>For example, I don't need to somehow ensure that the docker service itself stays up and running? I can trust that it stays alive?</p>
  
  <p>(Related question, but only about keeping docker running, not starting it on reboot: <a href="https://stackoverflow.com/q/24460717/694469">making sure a given docker container is running</a>)</p>
  
  <p>My host and container OS: Ubuntu 14.04.</p>