In this article, we will see how to get a Docker container’s IP address from the host using different methods.
We can get the docker container IP using inspect or by chekcing hosts file.
Find Docker container IP address
1. Simple run the docker inspect then container id or container name.
sudo docker inspect webpp1
sudo docker inspect 42d4fc6c0967
2. Run the below command and replace at the end with your container name or id
sudo docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_id or container_name
sudo docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' webapp1
For previous version run the below command.
sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' container_id or container_name
3. We can also check Docker container IP using below command.
sudo docker exec [container-id or container-name] cat /etc/hosts
sudo docker exec webapp1 cat /etc/hosts