Resolved: list all containers with restart policies

In this post, we will see how to resolve list all containers with restart policies

Question:

Is it possible to list all docker contianers with a restart policy set? I could inspect the running containers (How to quickly show policies of all docker containers), but what if one has been previously stopped, or has an on-failure policy and has completed successfully?

Best Answer:

I could inspect the running containers (How to quickly show policies of all docker containers), but what if one has been previously stopped, or has an on-failure policy and has completed successfully?


Exactly, so do not stop at running containers – inspect all containers.
Just list all containers with that policy.

How does docker system prune work with this?


It does not work with this (?).

Will it skip the removal of any containers that are stopped, but have a restart policy set?


No, a stopped container is also removed. Observe the following terminal transcript:

If you have better answer, please add a comment about this, thank you!

Source: Stackoverflow.com