2

First off, I am new to Docker. I was able to create a container based off an image I had previously pulled, start it, but the container is stopped if the docker daemon or the host system are restarted.

So the question is, what is the next step (after creating a container) to make it persistent so that it is started automatically when the daemon is started or restarted?

Thank you in advance.

  • docker run --help | grep restart combined with a reading of the fine manual should get you going in minutes. – Zeitounator May 29 at 16:46
  • @Zeitounator Thank you! You comment and the chosen answer were very helpful. – docker-noob Jun 1 at 16:51
1

You need to add a restart policy to your container.

example:

docker run -dit --restart=always hello-world

In this example, I am telling docker to always restart the hello-world container no matter what happens (and also run it in the background interactively). If you do a docker ps, you will see it keeps restarting. To revert this, you need to update the container restart policy like this:

docker update --restart=no <CONTAINER_ID>
  • Thank you so much! That did the trick! – docker-noob Jun 1 at 16:50
  • Glad to have been of help – gumol Jun 1 at 19:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.