Verify container running state [closed]

I have a bash script, which I use to run several Docker containers. Initialization time differs on system specifications, so sometimes these cannot be started in specified order. How can I detect with use of bash, that a container is running, so following container can be started. Containers requires previously started containers.

  • Make docker container run forever while being able to gracefully stop
  • Docker build auth error
  • Point different domains to different Docker containers on a single EC2 instance?
  • 'nutc': unknown terminal type. docker
  • Saltstack docker.login returns APIError: 500 Server Error?
  • docker mounted host directory file permissions
  • Docker impossible to link nginx container with php-fpm container
  • Docker - Feed data from read-only directory on host into container
  • In fedora container systemctl gives Failed to get D-Bus connection
  • how is docker better if tools like fedora's devassistant and virtualenv exist? [closed]
  • How to delete all running docker containers?
  • Kubernetes: Managing environment config
  • 2 Solutions collect form web for “Verify container running state [closed]”

    I wouldn’t recommend using bash for this. My ideal choice would be Ansible. But since your requirement is bash, so you’d do something like this (It’s not the exact code just an example):

    RUNNING=$(docker inspect --format="{{ .State.Running }}" $CONTAINER)
    while [ true ]; do
            if ["$RUNNING" == "true"]; then
                    echo "$CONTAINER is running. Now start your other container"
                    exit 0
                    echo "$CONTAINER is not running. Sleep for 1 second"
                    sleep 1

    you can find all the running containers with docker ps and filter them on various criteria with --filter=

    It is convenient to start a container with a --name
    the doc for docker run


    --name="" Assign a name to the container

    and you can then filter with docker ps --filter name=

    See the doc for docker ps

    an example

    docker ps --filter "name=captvty"

    you can also filter with the image, the label, the ancestor, the id…

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.