Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to show the restart policy of a running Docker container?

Tags:

docker

When I create containers I'm specifying a restart policy, but this is not shown in docker ps, and it doesn't appear any format string shows this either.

Does anyone know how to see the restart policy of a running container(s)?

like image 420
Steve Avatar asked Mar 30 '17 03:03

Steve


People also ask

How do I check my container restart policy?

Users can type docker ps to check if the restart policy is active; it will be shown as either Up , when the container is up and running, or Restarting when the container is in the restart state.

What is docker restart policy?

Docker provides restart policies to control whether your containers start automatically when they exit, or when Docker restarts. Restart policies ensure that linked containers are started in the correct order. Docker recommends that you use restart policies, and avoid using process managers to start containers.

How do I change the restart policy on a running container?

Find out the container ID, stop the whole docker service, modify /var/lib/docker/containers/CONTAINER_ID/hostconfig. json, set RestartPolicy -> Name to "always", and start docker service. docker commit your container as a new image, stop & rm the current container, and start a new container with the image.

How can I see what process is running inside a container?

Like it was mentioned, if you are already inside of a container, then just use ps -eaf command to see the running processes.


1 Answers

Yes, it is possible using docker inspect which is json format and just need to query it.

Here is relevant output of docker inspect for a running container zen_easley. Note to change container name as suitable for your environment.

  • docker inspect zen_easley
"HostConfig": {             "Binds": null,             "ContainerIDFile": "",             "LogConfig": {                 "Type": "json-file",                 "Config": {}             },             "NetworkMode": "default",             "PortBindings": {},             "RestartPolicy": {                 "Name": "no",                 "MaximumRetryCount": 0             },             "AutoRemove": true, 

You can just run the following command to get the same and its output.

$ docker inspect -f "{{ .HostConfig.RestartPolicy }}"  zen_easley {no 0} 

If you see RestartPolicy has two properties Name, MaximumRetryCount and no, 0 are the values respectively in the above output

You may also get the individual property value, say Name by using below command, appending .Name to the above command:

docker inspect -f "{{ .HostConfig.RestartPolicy.Name }}"  zen_easley no 
like image 104
Rao Avatar answered Oct 19 '22 09:10

Rao