Reputation: 11155
I have the bellow configuration with netwok bridge under mac siera.
I inspect the ipaddress docker gave to my mahcine (172.20.0.5).
But, when i ping 172.20.0.5
i get timeout.
Also the gateway gets timeout ping 172.20.0.5
version: "3.5"
networks:
main:
driver: bridge
name : main
services:
nginx_client:
networks: main
image: nginx
ports:
- "8080:80"
nginx_server:
networks: main
image: nginx
ports:
- "8081:80"
UPDATE
this is how i discovered the ip address
a-mac$ docker inspect docker_nginx_server_1 | grep 172
"Gateway": "172.20.0.1",
"IPAddress": "172.20.0.5",
Upvotes: 1
Views: 2177
Reputation: 346
A bridge network is used to isolate your container from your host network and that's why you're not able to ping from your host since your host and container is on different networks.
If you try the below command, you will find that it works:
docker run -it docker_nginx_server_1 ping 172.20.0.5
You can also try the following command to check if a specific port exposed on the container is working (Let's assume the port being 80):
telnet 172.20.0.5 80
For binding a port from your container to your host, you can do:
docker run -d -p 80:80 docker_nginx_server_1
This will bind the port 80 of your container to port 80 of your host so that you can access the nginx server from your browser like:
http://localhost
For more information about networking in docker, you can refer to the following link:
https://docs.docker.com/network/
Hope this helps.
Upvotes: 1