This Blog is to share our knowledge and expertise on Linux System Administration and VMware Administration

Sunday, January 21, 2018

Working with Docker Container - Setting the restart policy on a container

Setting the restart policy on a container

Restart policy is added with the run command with flags to specify the restart policy. With this policy, we can configure containers to start at boot time. This option is also very useful when a container dies accidentally.

Syntax:docker run --restart=POLICY [ OPTIONS ]  IMAGE[:TAG]  [COMMAND]  [ARG...] 

root@Docker:~# docker run --restart=always -d -i -t centos /bin/bash
fb83a04222c73d0e80f84103d4fe58c3ccd95e4a44b39386a937427bda2ad465

Options: 
no            : This does not start the container if it dies
on-failure : This restarts the container if it fails with nonzero exit code
always     : This always restarts the container without worrying about the return code

You can also give an optional restart count with the on-failure policy as follows:

root@Docker:~# docker run --restart=on-failure:3 -d -i -t centos /bin/bash
96b07463e85f3452cbbbf0de1298d4311634efef20f60a1d164e18f83ea19e15

For help with the docker run use --help

No comments:

Post a Comment