HomeClusterLabs Projects

Docker: fix docker existance test report error

Description

Docker: fix docker existance test report error

according to docker inspect --help, docker inspect may report information
for both container and image, if there's a image named "XYZ", and trying to
inspect "XYZ" w/o specifying --format {{.A.B.C}}, it would report image
state instead of container state.

$ sudo docker inspect --help

Usage: docker inspect [OPTIONS] CONTAINER|IMAGE [CONTAINER|IMAGE...]

Return low-level information on a container or image

and further more, we should judge if it is really a container,
here we use --format {{.State.Running}}, and more, we should judge if
it is really a container by determining return value, if it is a container,
we should get a string of boolean value "true" or "false", and we can tell it
is a Docker container, but not a Docker image.

if it is a Docker image,
$ sudo docker inspect --format {{.State.Running}} ubuntu:latest

<no value>

if it is a running Docker container,
$ sudo docker inspect --format {{.State.Running}} my_container

true

if it is a stopped Docker container,
$ sudo docker inspect --format {{.State.Running}} my_container

false

Details

Provenance
guessi <guessi@gmail.com>Authored on Jun 12 2015, 11:32 PM
Parents
rR3982a346dae5: Docker: remove trailing spaces
Branches
Unknown
Tags
Unknown

Event Timeline