Docking network on the same host with the layout

I am trying to run docker networking with compilation in docker 1.9. I know this is still experimental in 1.9, but I would like to know if my use case can work.

In principle and for simplification, I have two servers, each of which is in the container. Let them be called S1 and S2. S1 opens globally and must be accessible from S2. I want to start S2 via docker-compose with the -x-networking flag (the reason I want it to be that S2 is actually a bit more complicated than what is supposed here with multiple containers, and I want so that they run on the same subnet). S1 can work with or without layout.

What I understand from docker networks is that any container can reach another from the same network or can reach everything that is "globally" displayed through host port mapping, right?

So my scenario is:

  • I manually start S1 with port mapping, for example "-p 7210: 7202" (7202 is displayed in the docker file)
  • S2 is created from a simple layout file and updated using the - x-networking flag. For my test case, I created a very minimal layout file, for example:
S2:
    build: .
    ports:
        - "8080:80"

Results:

  • S1 does not display from S2 under "localhost" (this is to be expected)
  • S1 is not displayed with S2 in the section "172.17.0.1" (= docker0 interface)

I would expect that I could achieve this in accordance with 172.17.0.1, since S1 uses docker0, as I understand it.

, S2 , " ", S1, 172.17.0.1

? - , ?

+4
1

:

. -x-networking 1.6. , Docker compose .


, Docker .

. -x-networking docker-compose.

It Docker 1.9, :

https://docs.docker.com/engine/userguide/networking/dockernetworks/

, .

└── demo
    └── docker-compose.yml

docker 1.9.0 docker-compose 1.5.0

-compose.yml

, "web1" "web2". , tomcat.

web1:
  image: tomcat:8.0
  ports:
    - 8080
web2:
  image: tomcat:8.0
  ports:
    - 8080

docker compose

$ cd demo
$ docker-compose --x-networking up -d
Creating network "demo" with driver "None"
Creating demo_web2_1
Creating demo_web1_1

, "demo", -x-network.

,

"" , hosts.

$ docker-compose ps 
   Name           Command       State            Ports          
---------------------------------------------------------------
demo_web1_1   catalina.sh run   Up      0.0.0.0:32773->8080/tcp 
demo_web2_1   catalina.sh run   Up      0.0.0.0:32772->8080/tcp 

$ docker exec -it demo_web1_1 cat /etc/hosts
..
172.18.0.2  demo_web2_1

$ docker exec -it demo_web2_1 cat /etc/hosts
..
172.18.0.3  demo_web1_1

, "demo":

$ docker run --net demo --name helloworld -d tomcat:8.0

,

$ docker exec -it demo_web1_1 cat /etc/hosts
..
172.18.0.2  demo_web2_1
172.18.0.4  helloworld

$ docker exec -it demo_web2_1 cat /etc/hosts
172.18.0.3  demo_web1_1
172.18.0.4  helloworld

$ docker exec -it helloworld cat /etc/hosts
172.18.0.2  demo_web2_1
172.18.0.3  demo_web1_1
+9

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


All Articles