Issues with Network connectivity with Docker - docker

I am facing issues configuring network in docker. Details are given below.
Host Machine:- Ubuntu Server 14.04 LTS 64-bit. IP subnet: 10.0.0.0/16, IP address: 10.0.0.206/16 and default gateway: 10.0.0.1/16. This machine having docker installed (version 1.6.2 build 7c8fca2) and has a default IP in the docker0 bridge of 172.17.42.1/16. However, the container has received the IP as 172.17.0.1. Problems are as follows.
My Host machine and docker container is able to connect with each other and to Internet but any other machines are not able to connect with docker container.
Changing the docker0 bridge IP is temporary and reverts back to 172.17.42.1/16 once every reboot.
I cannot set a static IP address of my container as it changes automatically at every exit or if the host is rebooted. Checked the container's network config file /etc/network/interfaces but doing changes in this file has no effect to its eth0 interface.
In very short, I am not able to connect to the container from outer world (from other physical machines) even when I have configured the networking interface of other machines to connect to docker host and container.
How can I fix this connection problem?

By default, Docker containers can not be accessed from other host. And the IP address is allocated by docker.
You can use "--net=host" when run containers, then the container will share the same IP address with the host node. And the container will be available from other node.
docker run -it --net=host ubuntu bash

Related

ip address is accessible from docker host, but not from docker container running on the host

There's some virtual machine internal network ip address which is accessible from MAC docker host. This was verified using ping.
However, the same ip address is not accessible from any docker container running on the Docker host.
I tried to run container with --network host, however the ip is still not reachable.
Then, I discovered that none of the VMs reachable from MAC docker host are reachable from any docker container running on it.
How to debug and solve this issue?
External ip addresses (of google.com ) are accessible from the container.
I performed the same test on Linux docker host. The same internal VM ip address was reachable from within the container as well as all other VMs.
It's important to note that MAC docker host is just MAC machine connecting to the network using VPN and thus getting access to internal network VMs.
Linux Docker host is VM itself in the internal network where VMs are located.
I'm using 3.6.0 MAC Docker desktop version and update regularly.

How to access a docker container on host from local VM?

I have a docker container set up on the host with RabbitMQ installed and I'm trying to connect to that container and access the RMQ web UI from a Hyper-V VM. The docker container has a static ip assigned and is connected to a transparent network adapter while the VM is connected to an ethernet network adapter. I am new to networking so I have no idea how to connect the VM to the container. I've tried docker swarm but that gave me a deadline exceeded error so now I'm exploring port forwarding with the docker container or configure the VM to use bridged network mode, both of which I have no experience in. Pinging the docker container from host succeeds and so does pinging the host from VM but not the other way around. Some help would be appreciated.

How to ping docker container from VM on the same host?

I have a docker container and a virtual machine(VM) on the same host(OpenSUSE). the docker has the IP like 172.18.0.2 and the host IP is something like 3.204.XX.XX and VM IP is also something like 3.204.xx.xx, I am able to ping the docker from the host and even the VM is pingable from the host and vice-versa but I am unable to ping the docker from the Virtual machine present on the same host. Is there a way to access the docker on the host from the VM present on the same host? please help.
it is not possible directly because docker creates its bridge "bridge0" all the traffic is been routed using nat, where as virtualbox also creates its own bridge/interface , because of which its not able to access. But you can access by exposing port.
above mention requirement is possible with consul service discovery and host n/w config modification

Docker: Connectivity between Physical Machine - VM -Docker container

I have just started to have some experimentation with docker.
On my Windows host I have a virtual machine which holds a docker container. I want to have a communication between host and container or may be other VMs and this container.
Host ip is 192.168.2.10 with subnet mask 255.255.255.0
VM ip is 192.168.254.130 with subnet mask 255.255.255.0
Container gets an ip 172.17.0.13
I have seen few blogs talking about bridging but I am still not sure about it and how to do that. I am not very much into networking stuff.
A little guidance will help.
Thanks
EDIT:
I followed this bridge-building but could not understand what ip range to give to bridge, so, I gave 192.168.254.1/24. The command ip addr show bridge0 shows state UNKNOWN.
The normal way to do this is just to publish a port on the container and use the IP of the VM e.g:
docker run -d -p 80:80 nginx
Then visit the IP of the VM in a browser running on your host and you should get the webpage.
I'll assume you are using Docker on Windows with Linux host running on Virtualbox. Note that by default docker-machine creates a NAT adapter (with a port forward) and a host-only adapter, sometimes it is tricky to get different machines to talk to the correct ip.
As answered by Adrian you typically "publish" ports by port forwarding, but if your container has to communicate via many ports and you are only running one such container / host it could be easier to start the container via docker run --net host ..., this way host's ethernet adapters are directly visible within the container (as I discovered here).

Docker access port running on host

I'm using boot2docker and am running a docker container. I'd like for that docker container to be able to talk to my host who has an open port. I've tried hitting the host box, but its going through virtualbox so it seems there needs to be two levels of bridging here to get the ports to talk. Not sure how to do that, or even if its possible.
Actually you are right, there are 2 levels:
Host <-> boot2docker VM <-> docker container
so if you open a port while you run your container, the port can be accessed from boot2docker VM but not the host, unless you make a port forwarding.
and here are two solutions:
access using boot2docker VM's ip but not localhost
run boot2docker ip and you will see an ip address such as 192.168.59.103, then you can access your service through 192.168.59.103:port
make a port forwarding
open your VirtualBox application, select virtual machine namely boot2docker-vm, goto Settings->Network->Advanced->Port Forwarding. Then you can add your own port to forward, for example, i'd like to access my ssh port through localhost:10022, just simply add a new column with host port 10022 and guest port 22.
you can check this doc for more infos.
if you want access host port from container, here is a simple way, just expose your host ip to docker container's host, like docker run --add-host vmhost:192.168.59.3 <docker_image> <command>, note that 192.168.59.3 is the default virtualbox host only adapter IP. Then you can access vmhost as you want.
Also, you can manage your own network bridge to do this, and pipework may help you.

Resources