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)?
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.
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.
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.
Like it was mentioned, if you are already inside of a container, then just use ps -eaf command to see the running processes.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With