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.

  • How do pods in Google Container Engine talk/link to each other
  • mysql docker container get remote host: Connection refused after container running
  • Unable to delete some untagged docker images
  • How to replace a Docker data volume with another at runtime?
  • docker odoo 9 install pika error
  • docker-machine: Can't access container's web server from host
  • Docker: how control docker service on host from it's container?
  • How can I run Ghost in Docker with the google/node-runtime image?
  • Tomcat freezes in Docker container when starting
  • ECS updating service with same tasks but different docker image
  • Unix sockets vs TCP sockets in docker
  • Docker beta for Windows and Windows Bash: path must be absolute
  • 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):

    CONTAINER=my_container_id_or_name
    
    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
            else
                    echo "$CONTAINER is not running. Sleep for 1 second"
                    sleep 1
            fi
    done
    

    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

    https://docs.docker.com/engine/reference/commandline/run/

    extract

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

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

    See the doc for docker ps

    https://docs.docker.com/engine/reference/commandline/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.