Bash Script to check if a Docker container running

Method 1:

docker ps | grep <container_name>
Code language: Bash (bash)

Method 2:

if [ "$( docker container inspect -f '{{.State.Running}}' <container_name> )" == "true" ]; then ...
Code language: Bash (bash)

Method 3:

if [ "$( docker container inspect -f '{{.State.Status}}' <container_name> )" == "running" ]; then ...
Code language: Bash (bash)

Method 4:

if [ ! "$(docker ps -q -f name=<container_name>)" ]; then
Code language: Bash (bash)

Method 5:

if [ "$(docker ps -aq -f status=exited -f name=<container_name>)" ]; then # If stopped
Code language: Bash (bash)

Posted

in

,

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *