D
D
Dim Boy2020-01-07 23:29:47
Docker
Dim Boy, 2020-01-07 23:29:47

How to link a docker compose container to another one?

In all containers, I have created and registered a network, but I can not connect from this container to another. links are not suitable, since they are individually created and work.

networks:
  default:
    external:
      name: nginx-proxy

I read that you can create an alias for each container, but I can't figure out how.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Z
zohan1993, 2020-01-08
@zohan1993

The essence of the problem is not entirely clear and why everything is implemented in this way ...
If I understood the scheme correctly:
1. Create a network - nginx-proxy
2. Create a container using the already created network - 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. Checking connectivity between containers
# 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": ""
            }

G
great_77, 2020-01-08
@great_77

Via links - linking
Via volume - forwarding files outside the docker.
I didn't quite understand the question.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question