How to check whether docker is running normally

WBOY
Release: 2022-01-17 15:06:31
Original
20207 people have browsed it

In docker, you can use the "Docker ps" command to detect whether docker is running normally. This command is used to list the containers. If the returned result has content, it means it is running. If the return result has no content, it means it is not running. The syntax is " docker ps | grep myimagename".

How to check whether docker is running normally

The operating environment of this tutorial: linux7.3 system, docker-1.13.1 version, Dell G3 computer.

How to check whether docker is running normally

docker ps: list containers

Syntax

docker ps [OPTIONS]
Copy after login

OPTIONS description:

  • #-a: Display all containers, including those that are not running.

  • -f : Filter the displayed content based on conditions.

  • --format: Specify the template file for the return value.

  • -l : Display recently created containers.

  • -n: List the recently created n containers.

  • --no-trunc: Do not truncate the output.

  • -q: Silent mode, only the container number is displayed.

  • -s: Display the total file size.

How to determine if they are running? I can easily use docker ps from the terminal like:

docker ps | grep myimagename
Copy after login

If anything is returned, the image is running. If an empty string is returned, the image is not running.

However, I don't understand how to get subprocess.Popen to handle this - it requires a parameter list so something like:

    p = subprocess.Popen(['docker', 'ps', '|', 'grep', 'myimagename'], stdout=subprocess.PIPE)
    print p.stdout
Copy after login

doesn't work because it's trying to get "docker ps" and make It becomes the "docker" and "ps" commands (not supported by docker).

It seems I can't give it the full command either, because Popen tries to run the entire first argument as an executable, so this fails:

    p = subprocess.Popen('docker ps | grep myimagename', stdout=subprocess.PIPE)
    print p.stdout
Copy after login

Recommended study:《 docker video tutorial

The above is the detailed content of How to check whether docker is running normally. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!