I am new to docker. I am writing a simple script for docker. I need to check whether docker is running or not. Is there a command to check with container name
相关问题
- Docker task in Azure devops won't accept "$(pw
- JQ: Select when attribute value exists in a bash a
- Unable to run mariadb when mount volume
- Unspecified error (0x80004005) while running a Doc
- What would prevent code running in a Docker contai
Sometimes you don't know the full container name, in this case this is what worked for me:
We list all the running container processes (docker ps -a would show us also not running ones, but that's not what I needed), we search for a specific word (grep part) and simply count the lines of the result (wc -l), if it's greater than 0 it means we found some running containers which names contain our keyword.
List all containers:
docker container ls -a
ls
= list-a
= allCheck the column "status"
on a Mac you might see the image:
if you right click on the docker icon then you see:
alternatively:
docker ps
and
docker run hello-world
You can also check if a particular docker container is running or not using following command:
This command will check if for example my postgres container is running or not and will return output as "Running": true
Hope this helps.
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
You can check with this command
systemctl status docker
it will show the status of the docker. If you want to start you can usesystemctl start docker
instead ofsystemctl
you can try also withservice
,service docker status
andservice docker start
respectively.