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)
Leave a Reply