Не совсем понятна суть проблемы и почему все реализовано именно так...
Если правильно понял схему:
1. Создаем сеть - nginx-proxy
docker network create --subnet=192.168.111.0/24 nginx-proxy
2. Создаем контейнери с использованием уже созданой сети - nginx-proxy
docker-compose1.yml
-------------------------------
version: '3.7'
networks:
default:
external:
name: nginx-proxy
services:
busybox:
container_name: busybox
image: busybox
command: ping busybox2
busybox2:
container_name: busybox2
image: busybox
command: ping busybox
-------------------------------
docker-compose2.yml
-------------------------------
version: '3.7'
networks:
default:
external:
name: nginx-proxy
services:
busybox3:
container_name: busybox3
image: busybox
command: ping busybox
-------------------------------
docker-compose -f docker-compose1.yml up -d
docker-compose -f docker-compose2.yml up -d
# Запустим еще один контейнер руками
docker run -d --name busybox4 --network nginx-proxy busybox ping busybox3
3. Проверка связности между контейнерами
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
64ce2eb1f196 busybox "ping busybox3" 5 minutes ago Up 5 minutes busybox4
f67c1ef50ce7 busybox "ping busybox" 14 minutes ago Up 14 minutes busybox3
181aefcd78bb busybox "ping busybox2" 14 minutes ago Up 14 minutes busybox
428b7ba4c08f busybox "ping busybox" 14 minutes ago Up 14 minutes busybox2
# docker logs -f busybox
PING busybox2 (192.168.111.2): 56 data bytes
64 bytes from 192.168.111.2: seq=0 ttl=64 time=0.073 ms
64 bytes from 192.168.111.2: seq=1 ttl=64 time=0.112 ms
64 bytes from 192.168.111.2: seq=2 ttl=64 time=0.087 ms
# docker logs -f busybox2
PING busybox (192.168.111.3): 56 data bytes
64 bytes from 192.168.111.3: seq=0 ttl=64 time=1014.484 ms
64 bytes from 192.168.111.3: seq=1 ttl=64 time=14.449 ms
64 bytes from 192.168.111.3: seq=2 ttl=64 time=0.100 ms
# docker logs -f busybox3
PING busybox (192.168.111.3): 56 data bytes
64 bytes from 192.168.111.3: seq=0 ttl=64 time=0.093 ms
64 bytes from 192.168.111.3: seq=1 ttl=64 time=0.126 ms
64 bytes from 192.168.111.3: seq=2 ttl=64 time=0.127 ms
# docker logs -f busybox4
PING busybox3 (192.168.111.4): 56 data bytes
64 bytes from 192.168.111.4: seq=0 ttl=64 time=0.105 ms
64 bytes from 192.168.111.4: seq=1 ttl=64 time=0.107 ms
64 bytes from 192.168.111.4: seq=2 ttl=64 time=0.125 ms
# docker network inspect nginx-proxy
"Containers": {
"181aefcd78bbbc66c35757d6170d92a0ff753af91d4500d8405fc815ac5f3afe": {
"Name": "busybox",
"EndpointID": "ae472487064cf030f1df1c74e310bb3e82d3fe23912a3ffeeaf49902fb8b5b04",
"MacAddress": "02:42:c0:a8:6f:03",
"IPv4Address": "192.168.111.3/24",
"IPv6Address": ""
},
"428b7ba4c08f9ccf10563f064e96b8836bb9af31804ac00de30eb0c5f29eae80": {
"Name": "busybox2",
"EndpointID": "65e688e16d0d86f2244355e4608aa0e111d9178ff2cd509dc49855561b92faae",
"MacAddress": "02:42:c0:a8:6f:02",
"IPv4Address": "192.168.111.2/24",
"IPv6Address": ""
},
"64ce2eb1f196d012be0379ed46788e60a9a9534081d9985f8df2cc2cc1bb20d1": {
"Name": "busybox4",
"EndpointID": "c33d66f1004847e965b62c285c3afb5ec41972a083841b59b5300e8a5ba3de8a",
"MacAddress": "02:42:c0:a8:6f:05",
"IPv4Address": "192.168.111.5/24",
"IPv6Address": ""
},
"f67c1ef50ce705ba915c45dd0ee0e9a7f1f2ed8d90f19257dd7d12fffa5849cf": {
"Name": "busybox3",
"EndpointID": "921dc6d11fe07a89530080b0d8096b07f924c4cb0f3120201addc28a343dad74",
"MacAddress": "02:42:c0:a8:6f:04",
"IPv4Address": "192.168.111.4/24",
"IPv6Address": ""
}