then ,in your docker, install "ping/curl/ifconfig/telnet" , then type "ifconfig" to get your "docker" ip address, then type "ping <windows host ip" to see if the ip is correct.
Inspect the bridge network to see what containers are connected to it. Near the top, information about the bridge network is listed, including the IP address of the gateway between the Docker host and the bridge network ( 172.17. 0.1 ).
Usually Docker uses the default 172.17. 0.0/16 subnet for container networking.
If you don't want to map ports from your host to the container you can access directly to the docker range ip for the container. This range is by default only accessed from your host. You can check your container network data doing:
docker inspect <containerNameOrId>
Probably is better to filter:
docker inspect <containerNameOrId> | grep '"IPAddress"' | head -n 1
Usually, the default docker ip range is 172.17.0.0/16
. Your host should be 172.17.0.1
and your first container should be 172.17.0.2
if everything is normal and you didn't specify any special network options.
EDIT Another more elegant way using docker features instead of "bash tricking":
docker inspect -f "{{ .NetworkSettings.IPAddress }}" <containerNameOrId>
EDIT2 For modern docker engines, now it is this way (thanks to the commenters!):
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <containerNameOrId>
Use --format
option to get only the IP address instead whole container info:
sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' <CONTAINER ID>
For modern docker engines use this command :
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_name_or_id
and for older engines use :
docker inspect --format '{{ .NetworkSettings.IPAddress }}' container_name_or_id
if you want to obtain it right within the container, you can try
ip a | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b" | grep 172.17
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With