How to make the Docker container available to other network machines over IP?

I need to create several docker containers that other computers on the same network should access.

The problem is that when I create the container, Docker gets the IP addresses valid only on the host machine.

I already looked at the Docker (Networking) documentation, but nothing worked.

If I run ifconfig on my machine, my IP address will be 172.21.46.149 . When I go into 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 this?

+5
source share
3 answers

You need to create a bridge on your host and assign this bridge to the container. This may help you: https://jpetazzo.imtqy.com/2013/10/16/configure-docker-bridge-network/

+2
source

Access to multiple nodes includes an overlay network with service discovery .
See dockers / networks :

An overlay network requires a keystore . The store stores network status information, which includes discovery, networks, endpoints, IP addresses, etc.
The Docker Engine currently supports Consul, etcd, ZooKeeper (Distributed store) key store stores, and BoltDB (Local store) key store stores.
This example uses Consul.

https://github.com/docker/dceu_tutorials/raw/master/images/tut6 -step1.png

If your nodes (other computers on the same network) launch their docker daemon with a link to this keystore, they will be able to communicate with containers from other nodes.

 DOCKER_OPTS="-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock --cluster-store=consul://<NODE-0-PRIVATE-IP>:8500/network --cluster-advertise=eth0:2375" 

You just need to create an overlay network:

  docker network create -d overlay --subnet=10.10.10.0/24 RED 

(it will be available on all computers due to the storage of key values)

And run your containers on this network:

 docker run -itd --name container1 --net RED busybox 
+2
source

Docker containers can be easily accessed by another node network when the container: port is published through host :.

This is done using the -p docker-run option. Here is a selection of the man page ( $man docker-run gives more details and an example that I will not copy / paste):

  -p, --publish=[] Publish a container port, or range of ports, to the host. 

Watch the doc online . This question may be interesting to read.

Basically:

docker run -it --rm -p 8085:8080 my_netcat nc -l -p 8080

Allows LAN nodes to connect to docker-host-ip: 8085 and discuss with the netcat command.

+1
source

Source: https://habr.com/ru/post/1244125/


All Articles