Enhancing Skills

Docker container IP address

To be able to view the container informaion, you must be root.

sudo su

To see the IP addresses of all Docker containers running on your Linux system, you can use the following command:

docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $(docker ps -aq)

The output of the command will be a list of IP addresses, one per line, corresponding to each running Docker container.

This command will first list all running Docker containers using docker ps -aq and then run the docker inspect command on each container to extract the IP address of each container. The -f option is used to specify a Go template that extracts the IP address from the container’s network settings.

To include the container name along with its IP address in the output, you can modify the command as follows:

docker inspect -f '{{.Name}} - {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $(docker ps -aq)

This command uses the same docker inspect command to extract the IP address of each container, but it also includes the {{.Name}} template variable to display the name of the container in the output.

The output of the command will be a list of container names and their corresponding IP addresses, with each line in the format container_name - IP_address.

To quit root:

exit

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.