Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to access local network IP from docker container

Running macOS and docker ubuntu on it, I am unable to ping my local network's IP addresses. Below is the network configuration of my docker container. I can ping my host machine's IP address but I am unable to access other IP addresses on the local network.

root# ping 172.17.101.192
PING 172.17.101.192 (172.17.101.192) 56(84) bytes of data.
From 172.17.0.3 icmp_seq=1 Destination Host Unreachable
From 172.17.0.3 icmp_seq=2 Destination Host Unreachable

root# ifconfig         
eth0      Link encap:Ethernet  HWaddr 02:42:ac:11:00:03
          inet addr:172.17.0.3  Bcast:0.0.0.0  Mask:255.255.0.0
          inet6 addr: fe80::42:acff:fe11:3/64 Scope:Link

Is there any network configuration which would help me to perform this operation?

I have tried net=host but it is not helping it.

like image 313
badal16 Avatar asked Dec 15 '16 16:12

badal16


People also ask

What is my host IP address on the default docker0 bridge network?

Most Docker Engine installations will represent the host as 172.17.0.1 on the default docker0 bridge network. You can check your own IP by running this command on your host: Your host’s Docker IP will be shown on the inet line. Connect to this IP address from within your containers to successfully access the services running on your host.

Can we access host Service(s) from inside a docker container?

This might be a really weird or edge case scenario, but what If we need to access host service (s) from inside a Docker container. For instance, we already have configured and running a service on the dev host machine and kinda lazy to dockerize it. Docker supports a host-gateway reference to the host’s gateway.

How do I get the IP address of a docker container?

In a script called docker-ip, place the following: And now we can get the ip address of a container like this: This uses the standard Docker network model combined with NAT rules on your host to redirect inbound traffic to/outbound traffic from the appropriate IP address. Assign our target address to your host interface:

Why can't I run Docker on my local network?

I think docker internal network could be conflicting with your local network addressing. Try to run Docker changing the default internal network to something that doesn't conflict, as 172.31.0.0/24.


1 Answers

I was using docker for mac, the issue was docker internal network conflicting with my local network addressing. To resolve the this issue, i need to go to Preferences in the dokcer menu. In Preferences menu Daemon>Advanced Menu, i can supply other bip.

{
    "bip" : "12.12.0.1/24"
}

Click apply and restart. The next time docker will start with internal network as 12.12.0.1/24.

like image 86
badal16 Avatar answered Nov 02 '22 07:11

badal16