Get the ip address of docker and docker-compose containers

For example, if we want to get the IP address of a container named my_container, we would use the following command:

docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' my_container 

This will return the IP address of the container.

If you’re using docker-compose, you can also use the docker-compose port command. This command will return the mapped port for a given container’s internal port.

For example, if we want to get the external mapped port for a container named my_container [with internal mapping of 8080], we would use the following command:

docker-compose port my_container 8080 

This will return the mapped port for the container. In this example, it would return 8080 if the config has:

ports:
      - 8080:8080

You can also use the docker-machine ip command to get the IP address of a Docker host. This is useful if you’re using Docker Machine to create your Docker hosts.

For example, if we want to get the IP address of a Docker host named my_host, we would use the following command:

docker-machine ip my_host

This will return the IP address of the Docker host. There are a few ways to get the IP address of a Docker container.

The docker inspect command is the easiest way to do it.

If you’re using docker-compose, you can use the docker-compose port command. And if you’re using Docker Machine, you can use the docker-machine ip command.

If you’re really struggling to understand your system and want to take a look at everything. Here is a command line utility that can help:

docker run --rm -ti \
  --name=ctop \
  --volume /var/run/docker.sock:/var/run/docker.sock:ro \
  quay.io/vektorlab/ctop:latest

Leave a Comment

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

Scroll to Top