Docker Container Onboot Policy - How to make sure a container is always running

Generally most containers are by default set not to start automatically.

Ther eare 3 settings for the "RestartPolicy" of containers: 

    no: Do not automatically restart the container (default).
    always: Always restart the container regardless of the exit status.
    unless-stopped: Always restart the container unless it is explicitly stopped.
    on-failure: Restart the container only if it exits with a non-zero status

Here is how you can see the policy:

docker ps -aq | xargs -I {} docker inspect --format='{{.Name}}: {{.HostConfig.RestartPolicy.Name}}' {}
 

We can see the output of all containers on the node and in the case below we see that all 3 are set to "no".

/festive_wiles: no
/magical_goldberg: no
/angry_hamilton: no

Say if we wanted "festive_wiles" to always be running (eg. if the server/node is rebooted we want the container to startup automatically):

docker update --restart=always festive_wiles

How can set these startup/restart settings when creating the container?

We just specify --restart=

docker run --name YourContainerName --restart=always -d nginx


Tags:

docker, container, onboot, runninggenerally, containers, default, automatically, ther, eare, settings, quot, restartpolicy, restart, regardless, explicitly, exits, ps, aq, xargs, inspect, format, hostconfig, output, node, festive_wiles, magical_goldberg, angry_hamilton, eg, server, rebooted, startup, update, creating, specify, yourcontainername, nginx,

Latest Articles

  • How to combine .txt ACLs without breaking things
  • How to ping all of Googlebot's IPs script
  • 'virtio0' uses a qcow2 feature which is not supported by this qemu version: QCOW version 3
  • Linux bash script to get the IP of a list of hostnames
  • How To Use Camera Webcam in Docker for OBS Studio etc...
  • Computer Server Won't Post Boot Or Enter BIOS Setup After Installing RAID SAS or GPU Card etc..
  • How To Test PHP Scripts from CLI with GET variables/query string
  • apt-cache how to see all available versions of a package in Debian Ubuntu Mint
  • Virtualbox VBox Guest-utils drag and drop files stops working with Windows VMs
  • How To Remove Ubuntu Netplan and Go Back to /etc/network/interfaces
  • How To Force Flash an AMD Instinct GPU To Another Model Using Debian Ubuntu Mint Linux
  • How To compile ollama from source to use unsupported AMD GPU with rocm in Ubuntu Debian
  • QEMU KVM Virtio GPU Windows Cannot Select 1080P
  • Linux Gnome Desktop Ubuntu Mint Debian Gets Slower After Weeks
  • Firefox How to Save Full Page As Screenshot/PDF
  • Nvidia Datacenter Driver Tesla Slow nvidia-smi response and high utilization with 0 usage
  • ffmpeg how to normalize / increase the volume of your audio
  • kdenlive audio blips pops cracks artifacts solution fix
  • haproxy / nginx certbot SSL issues
  • nginx how to see the real IP when behind a CDN