Docker Container IP
The snippet can be accessed without any authentication.
Authored by
Hermann Mayer
Edited
docker-id 432 B
#!/bin/bash
#
# Find a container/pod id by fuzzy name/id.
if [ -z "${1}" ]; then
echo 'Container name is missing.'
exit 1
fi
# $1-n - the regex (pcre) pattern
function filter()
{
docker ps --format '{{.ID}}|{{.Names}}' \
| grep -P "${@}"
}
if [ $(filter "${@}" | wc -l) -gt 1 ]; then
filter "${@}" --color=always >&2
echo >&2
echo "Error: Ambiguous match for: ${@}" >&2
exit 1
fi
filter "${@}" | cut -d '|' -f1
docker-ip 333 B
Please register or sign in to comment