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.

  • Is it possible for a the host to authenticate to a KDC running on a Docker container?
  • Large memory usage despite vm_memory_high_watermark being set
  • Kubernetes locally via Docker: why do we need port forwarding?
  • questions about docker --link parameter
  • Docker-compose fails with error “No command specified”
  • Rancher: Unsupported config option for xxx service: 'upgrade_strategy'"
  • How to connect Docker Swarm to multiple consul servers for failover?
  • Get bridge name associated to docker Network
  • How can I load the docker images before the service starts?
  • How to do --rm and --restart in dockerfile?
  • Docker: hashicorp/boot2docker fails to download behind corporate proxy
  • How to provide user defined argument and value in docker run?
  • 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.