tested on Arch Linux x64 4.5.4-1-ARCH
Ever needed the IP of your running docker container? I found a script somewhere on Stackoverflow, packed it into a function and created an alias for it. This function is just a shorthand to get the IP by container ID or by the container's name:
Append this to your .bash_aliases
or similar:
# ~/.bash_aliases
docker-ip() {
docker inspect --format '{{ .NetworkSettings.IPAddress }}' "$@"
}
and load it into your current session:
$ source ~/.bash_aliases
Now you have access to the new command docker-ip
and you can feed it with the container name or ID.
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4f4622efdeb8 dockercomposephpmysql_web "php -S 0.0.0.0:8000 " 10 minutes ago Up 10 minutes 0.0.0.0:8000->8000/tcp dockercomposephpmysql_web_1
bc1e298a9890 mysql "/entrypoint.sh mysql" 10 minutes ago Up 10 minutes 0.0.0.0:3306->3306/tcp dockercomposephpmysql_db_1
$ docker-ip 4f4622efdeb8
172.17.0.3
$ docker-ip dockercomposephpmysql_web_1
172.17.0.3
Now open your browser at http://172.17.0.3:8000.