I need to create some docker containers that must be accessed by other computers at the same network.
Problem is that when I create the container, Docker gets IP addresses valid only within the host machine.
I already took a look at Docker documentation (Networking) but nothing has worked.
If I run ifconfig
on my machine my IP address is 172.21.46.149
. When I go inside the container (Ubuntu) and run ifconfig
the IP address is 172.17.0.2
. I need Docker to get, for example, 172.21.46.150
.
How can I do it?
You have to create a bridge on your host and assign that bridge to the container. This may help you: https://jpetazzo.github.io/2013/10/16/configure-docker-bridge-network/
Docker containers can easily be accessed by other network node when a container:port is published through a host:port.
This is done using the
-p
docker-run option. Here is the sum-up of the man-page ($man docker-run
gives more details and example that I won't copy/paste):See the doc online. This question/answer could be interesting to read too.
Basically:
docker run -it --rm -p 8085:8080 my_netcat nc -l -p 8080
Would allow LAN nodes to connect to the docker-host-ip:8085 and discuss with the netcat command.
Multi-host access involves an overlay network with service discovery.
See docker/networking:
If if your your nodes (the other computers across the same network) runs their docker daemon with a reference to that key-value store, they will be able to communicate with containers from other nodes.
You just need to create an overlay network:
(it will be available in all computers because of the key-value store)
And run your containers on that network: