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

  • Proxmox How To Purge Ceph
  • VMWare ESXi/VSphere Disable Balloon Segfault in Services Solution
  • Apache Linux Debian Ubuntu Container how to manually restart without killing
  • Docker enable UTF8 in Container to stop seeing gibberish ? characters
  • Debian 8 How To Use Apt Update Archive sources.list
  • Debian Live CD Password
  • Forbidden You don't have permission to access this resource. [authz_core:error] [pid 338:tid 338] [client 1.2.3.4:55046] AH01630: client denied by server configuration:
  • The client needs a new connection for this request as the requested host name does not match the Server Name Indication (SNI) in use for this connection.
  • Asterisk RTP/audio not working in either direction in Docker NAT with a NAT client
  • dovecot: imap(root@localhost)<3702>: Error: Mailbox INBOX: mmap(size=352609044) failed with file /var/spool/mail/root/Maildir/dovecot.index.cache: Cannot allocate memory
  • Asterisk cannot find soundfile file.c:824 ast_openstream_full: File for-tech-support does not exist in any format
  • Apache Error solution - mktemp: failed to create directory via template '/var/lock/apache2.XXXXXXXXXX': No such file or directory
  • sysctl settings to reduce buffers and caches in Linux
  • Find /dev/sd block device of ata device - ata6: SATA link up 1.5 Gbps (SStatus 113 SControl 310) ata6.00: qc timeout (cmd 0xec) ata6.00: failed to IDENTIFY (I/O error, err_mask=0x4) ata6.00: revalidation failed (errno=-5)
  • Stuttering Audio on VOIP phones when first answering a call slow and fast audio
  • How to distribute the Microsoft VC Visual Studio Redistributable Files On Your Own
  • Nvidia video resolution and codec encode decode support matrix eg. h264 4k h265 HEVC VP9 Card List from GTX, RTX, Quadro
  • Japan and China ping time observations
  • ffmpeg convert to another format eg h265 to h264
  • Apache stop bots and hackers by using forensic logging.