Changing Docker container restart behavior

There are times when you want existing or running Docker containers to be started automatically every time you launch Docker. There are also times when you want to revert this behaviour.

  • To tell Docker to restart an existing container automatically whenever it quits and to start it automatically when Docker starts:

    docker update <container-name> --restart always

  • To tell Docker to stop starting the existing container automatically:

    docker update <container-name> --restart no

  • To tell Docker to start an existing container automatically (but still allows you to quit it manually) - optionally specify the number of tries:

    docker update <container-name> --restart on-failure

    docker update <container-name> --restart on-failure:3