In a script, I need to check:
a) Is the docker engine running?
b) Given a container name, is that docker container running?
[the initial wording of this
container status: true/false
# docker inspect --format '{{json .State.Running}}' container-name
true
#
For OS X users (Mojave 10.14.3)
Here is what i use in my Bash script to test if Docker is running or not
# Check if docker is running
if ! docker info >/dev/null 2>&1; then
echo "Docker does not seem to be running, run it first and retry"
exit 1
fi
Run this command in the terminal:
docker ps
If docker is not running, you wil get this message:
Error response from daemon: dial unix docker.raw.sock: connect: connection refused
For the answer to your first question refer to this answer - https://stackoverflow.com/a/65447848/4691279
For your second question - you can use command like docker ps --filter "name=<<<YOUR_CONTAINER_NAME>>>"
to check whether a particular container is running or not.
If Docker and Container both are running then you will get output like below:
$ docker ps --filter "name=nostalgic_stallman"
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9b6247364a03 busybox "top" 2 minutes ago Up 2 minutes nostalgic_stallman
If Docker is not running then you will get an error message saying docker daemon is not running.
If Docker running but Container is not running then you will not get the container name in the output of this command.
Any docker command (except docker -v
), like docker ps
If Docker is running, you'll get some valid response, otherwise you'll get a message that includes "Is your docker daemon up and running?"
You can also check your task manager.
Run:
docker version
If docker is running you will see:
Client: Docker Engine - Community
Version: ...
[omitted]
Server: Docker Engine - Community
Engine:
Version: ...
[omitted]
If docker is not running you will see:
Client: Docker Engine - Community
Version: ...
[omitted]
Error response from daemon: Bad response from Docker engine