CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES3b733ae18c1c parzee/database "/usr/lib/postgresql/" 6 minutes ago Up 6 minutes 5432/tcp serene_babbage
#!/usr/bin/env python# Coding: utf-8# Save this file like get-docker-ip.py in a folder that in $PATH# Run it with# $ docker inspect <CONTAINER ID> | get-docker-ip.py
import jsonimport sys
sys.stdout.write(json.load(sys.stdin)[0]['NetworkSettings']['IPAddress'])
If in case you can't remember the above command you can always do the following
docker inspect containerID
It will Return low-level information on Docker objects after the information is returned look for "Networks" and inside it you will find "IPAddress" of container
#!/bin/bash
# Only need to set "CONTAINERNAME" variable with an arbitrary# string found in either the Container ID or Image Name and# it prints container IP. Ensure the string is unique to desired host
CONTAINERNAME='mariadb-blog'CONTAINERID="$(docker ps | grep -i $CONTAINERNAME | awk '{print $1}')"CONTAINERIP="$(docker inspect -f '\{\{range.NetworkSettings.Networks}}\{\{.IPAddress}}\{\{end}}' $CONTAINERID)"
echo "$CONTAINERIP"