Issue with Docker0 on Vagrant - docker

I have an application that I have been deploying that gets the local ip address to open up ports for communication it does. It is running on a vagrant / virtualbox setup. Everything was good. I recently installed docker to run a DB container.
What I am finding is that the existing application when it tries to get its IP Address is finding the docker0 address 172.x.x.x and things start breaking. If I destroy the docker0 adapter (sudo ip link del docker0) things go back to working.
Is there a way so that when the java application asks for the ip address it does not return the docker address?

Thats how docker works. You could run the Container in the Host-Network so it will use the "VM" IP.
docker run my_container --net=host

Related

Docker for Windows connect Linux container to windows host network

first of all, I don't have much network experience or knowledge, especially regarding docker containers, so please be gentle.
I am running a host machine with docker for windows and need to start linux containers. Those linux containers get passed an environment variable with the IP of the server the service in the container needs to connect to. I suspect this part works, as the server registers that a client has connected with the IP 172.17.0.2 and looking up the ifconfig inside the container confirms this as it also shows IP 172.17.0.2.
I suspect that this IP got generated by some docker networking isolation stuff as this cannot be reached from outside.
Now to the problem.
The service running in linux container probably sends a notifaction to the server about it's existance and with it the local ip of the container. When the server tries to send a command to a registerd client it responds with find
Failed to find host 172.17.0.2
So, I need the docker container to use the the real IP of the windows host.
Instinctively, I turned to passing --network host as a parameter for docker run, but doesn't seem to be supported with docker for windows.
Passing the host's IP via --ip didn't work either as the interal container IP remained at 172.17.0.2.
These posts seems to be very related How to connect to docker host from container on Windows 10 (Docker for Windows)
Container can not resolve docker.for.win.localhost
, but --dns host.docker.internal or docker.for.win.localhost resulted in
invalid argument "host.docker.internal" for "--dns" flag:
host.docker.internal is not an ip address
am I maybe missunderstanding how to use them? Other ideas on solving the problem?

Issues with Network connectivity with 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

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 container not exposed on network

I am new to docker. I am running it on windows. I am trying to get a container named "ghost" (available from the Docker Hub) to work on a Windows 8.1 machine. While the container starts correctly and supposedly exposes url at http://localhost:2368, when I enter this address nothing happens. The same has happened when trying other containers from the Hub which expose urls.
I tried accessing the container's exposed URL from the IP Address I get from the "docker ip" but it failed too. I also tried running the container with the "--net="bridge"" option, to no avail. I think I'm missing something pretty basic, but I can't for the life of me figure out what. Can someone point me in the right direction?
When you install Docker on Windows that means you most likely installed boot2docker.
boot2docker starts a minimal Linux VM (based on VirtualBox) because Docker requires a Linux kernel to run. The Docker daemon is started on that VM and not on your localhost.
You can determine the VMs IP address by typing boot2docker ip on your command line. The standard boot2docker IP address is 192.168.59.103 if you did not configure something else or have multiple instances of that VM running.
So when you execute docker run --name ghost -p 2368:2368 -d ghost the port 2368 is opened at 192.168.59.103:2368. That is where you need to connect to.
For more information please read the official boot2docker documentation.
You haven't provided the complete 'docker run ...' command you executed, so I'm assuming you ran the one specified in the image's page on Docker Hub (reproduced below).
docker run --name some-ghost -p 8080:2368 -d ghost
The command is mapping Ghost's exposed port inside the container (2368) to port 8080 in your boot2docker VM. The first thing you need to do is run boot2docker ip to find out the IP address of your boot2docker VM. About the port number, you have two options:
Access Ghost via port 8080 (http://BOOT2DOCKER-IP:8080)
Change the port mapping to expose 2368 (-p 2368:2368)

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