Communication between windows and docker container on the same host

This may sound trivial, but after some trial error, I come to the SO community for a little help!

I create a network, I call it docker-net.

I have a linux container, let it all be LC1, which has a published port 6789 (so it had the -p 6789: 6789 option when it was created), and I force it to join the docker-net (--network docker-net) This works great, through my host, I can't communicate with it.

I switch to Windows containers and check that LC1 is still working. It does! Amazing.

I'm creating a container, let's call it WC1. It also publishes port 9000 which maps internally to 80 (-p 9000: 80)

An application inside WC1 is trying to connect to LC1 using an IP assigned from the network (docker is checking LC1) and I cannot connect.

There is probably a concept that I cannot dip into.

I understand that WC1 and LC1 have different gateways and subnets. Could this be the culprit?

Any help to get me to make this work appreciated!

EDIT: Here are the commands I followed for the above scenario:

docker network create docker-net
docker run -d -p 6789:6789 --name LC1 --network docker-net LC1
docker inspect LC1

      

IP address 172.18.0.2

go to windows container

docker run -d -p 9000:80 --name WC1 WC1

      

+3


source to share


2 answers


The docker network connect documentation states that you can assign an IP address to the container, the same should work with docker run -network name --ip. Then use that IP to access the container.



Specify the IP address that the container will use on this network

You can specify the IP address that you want to assign to containers.

$ dock connection --ip 10.10.36.122 multi-host-network container2

0


source


I found them:

and I think the only way to communicate with the two containers is through the host and expose the ports. For example, LC1 will use -p [your app port]:8080

WC1 as well -p [your app port]:9090

.



By [your app port]

that I mean it's up to you to decide what to use (tcp / udp listening socket, REST api ...)

How docker will evolve, maybe there will be a better solution in the near future.

0


source







All Articles