I have a local mosquitto broker running on ubuntu with bind_address localhost. If I try to access this broker from a docker container with node-red on the same host, it is not reachable. If I don't bind mosquitto to localhost, all works well.
What can I do to make mosquitto visible only on local machine but also accessible for local docker containers?
localhost in the docker container is not the same localhost as the machine running the Docker engine.
If you want to access the broker you will need to use the address of the host machine on the Docker virtual network (e.g. 172.17.0.1 bound to device docker0 is the default I think).
You can keep the bind_address entry, but you will need to add a second listener entry for the address bound to the docker0 interface.
Related
I have a Windows 10 Home machine (local machine) where I have installed Docker Toolbox that runs docker inside a VM. IP (192.168.0.6)
Also, there is another Windows 10 Pro machine (remote machine) that has Docker Desktop installed. IP (192.168.0.13). In the Docker Desktop setting, I have enabled "Expose daemon on tcp://localhost:2375 without TLS". At this point, I do not care about the TLS part since both the machines are on the local network. In the firewall setting, I have accepted inbound connections from port 2375.
Now I would like to run docker-compose from a local machine that connects and runs docker on the remote machine. To test connection, the command used on local machine is
docker -H tcp://192.168.0.13:2375 version
The response is
Cannot connect to the Docker daemon at tcp://192.168.0.13:2375. Is the docker daemon running?
I see that it calls https://192.168.0.13:2375/v1.40/info and not http://192.168.0.13:2375.
And in my remote machine, if I enter http://localhost:2375/v1.40/info I get a response but there is no response when I run by providing IP like http://192.168.0.13:2375/v1.40/info
I assume your docker daemon is only listening on localhost or 127.0.0.1.
You try to connect from another machine which connects to your machine with you internal network ip 192.168.0.13.
This means you need to configure your docker daemon to listen to:
192.168.0.13 = only network internal
tcp://192.168.0.13:2375
0.0.0.0 = all ip addresses
tcp://0.0.0.0:2375
In Windows you need to create a Docker-Daemon config file in:
C:\ProgramData\docker\config\daemon.json
with following content:
{
"hosts": ["tcp://0.0.0.0:2376"] # IP Address for container host
}
You can probably define a Subnet but i am not sure about this.
This is because the VM network interface is only binded to your localhost.
Try forwarding the port. From powershell or command prompt with admin privileges:
netsh interface portproxy add v4tov4 listenport=2375 listenaddress=192.168.0.13 connectaddress=127.0.0.1 connectport=2375
Is it possible to setup docker container on Linux so that it's accessible right from host on Windows 10 with container's ip?
My docker compose file is simple
version: '2'
services:
silo1:
hostname: silo1
image: 'silo'
ports:
- '11111:11111'
- '30000:30000'
Now to check container's ip address I run
# hostname -I
172.20.0.2
#
This container runs the service that is accessible from other containers on subnetwork 172.20.0.*, but my host computer on Windows 10 where Dockers are ran from can't ping the ip by any port including 11111, 30000
paping.exe 172.20.0.2 on TCP 11111:
Connection timed out
My host machine shows the following Network information:
IPv4 address: 192.168.0.22
IPv4 Subnet Mask: 255.255.255.0
Maybe the problem caused by host and container being on different local subnets? Is so, how can I configure docker container to assign 192.168.0.* ip to my container? I wonder how container picks port for containers, why is it 172.20* specifically?
I know that those ports are open through host machine, like container's service must be accessible with 192.168.0.22:11111, but I need to use ip assigned to container, not a host system.
Docker assigns IP addresses from its default bridge (172.20.0.0/16 in your case).
But Docker also let's you create a custom bridge network where you can choose the IP range.
More info here: https://docs.docker.com/network/bridge/
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
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
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.