Skip to content

wait-for-container-to-exit.sh script is not swarm friendly #3

Description

@johnmanko

With swarms, the container name is dynamic. More so, container_name in the compose file won't work with them. Perhaps a better way to search for a running instance of the WAITFORIT_CONTAINER is to look for an image ancestor. Below is an example where is looks for zero running containers. (I also locked the API version to v1.4 in case future versions of Docker change the default API):

wait_for()
{
  while :
  do

    INSPECT_CONTAINER=`curl --silent --unix-socket /var/run/docker.sock ${API_SERVER}/v1.40/containers/json?filters=%7B%22ancestor%22%3A%5B%22${WAITFORIT_CONTAINER}%22%5D%7D`

    INSPECT_CONTAINER_RESULT=$(jq --raw-output '. | length' <<< "${INSPECT_CONTAINER}")

    # echoerr $INSPECT_CONTAINER_RESULT

    if [[ $INSPECT_CONTAINER_RESULT == "0" ]]; then
      exec "${WAITFORIT_CLI[@]}"
      exit
    else
      sleep $WAITFORIT_TIMEOUT
    fi

  done
}

And it's usage would be something like:

    command: ["/wait-for-container-to-exit.sh", "jasperserver-ce-cmdline:7.8.0", "-t" , "30", "--", "/entrypoint-ce.sh", "run"]

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions