#!/bin/sh mode="once" if [ "$1" = "-w" ]; then mode="wait"; shift fi container_name="$1"; shift container_ip_addr="" sleep_interval='0.1' if [ "${mode}" = "wait" ]; then while :; do container_ip_addr=$(command docker inspect --format '{{.NetworkSettings.IPAddress}}' "${container_name}" 2>/dev/null) if [ -n "${container_ip_addr}" ]; then break fi sleep "${sleep_interval}" sleep_interval=$(echo "((${sleep_interval} * 2) % 10) + 0.1" | bc) done else container_ip_addr=$(command docker inspect --format '{{.NetworkSettings.IPAddress}}' "${container_name}" 2>/dev/null) fi if [ -n "${container_ip_addr}" ]; then echo "${container_ip_addr}" else exit 1 fi