How to check if the docker engine and a docker container are running?

前端 未结 17 1318
既然无缘
既然无缘 2021-01-30 05:03

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

17条回答
  •  难免孤独
    2021-01-30 05:29

    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=<<>>" 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.

提交回复
热议问题