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
Related
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?
I want to open port on docker container.
but not using docker run -p option.
because container have assigned independent IP address by bridge network.
so my system don't need port forwarding.
for example.
host OS has IP 172.30.1.2
container has IP 172.30.1.3
so I want to connect the container with 172.30.1.3:80 directly.
then, I tried something using iptables. but it is denied.
are there some way possible?
You can specify an IP endpoint when exposing ports. For example: -p 172.30.1.3:80:80
Check documentation here
I am currently using Docker Desktop for Mac.
My requirement is to spin off a container from another container.
Situation:
Container A has a service running which upon request looks for a swarm manager and spin off another container B. I have started single node swarm manager on my machine. I can not use host network_mode because docker for MAC exposes light weight linux vm as host and not my actual localhost. I have tried this also : https://forums.docker.com/t/access-host-not-vm-from-inside-container/11747/7
Any possible solution?
The idea is that your container can access your host. So, use the Engine API provided by Docker:
POST /containers/create
You will have to post json that contains the details of the new container.
Engine API v1.24
The daemon listens on unix:///var/run/docker.sock but you can Bind Docker to another host/port or a Unix socket.
You can listen on port 2375 on all network interfaces with -H tcp://0.0.0.0:2375, or on a particular network interface using its IP address: -H tcp://192.168.59.103:2375. It is conventional to use port 2375 for un-encrypted, and port 2376 for encrypted communication with the daemon.
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).
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.