Search code examples
dockerdocker-composedocker-network

Docker, communicating between hosts on different bridges


My case:

  • I have a container (container_A) on the default bridge network (172.17.0.1/16)
  • I have a group of containers -- created through docker-compose -- on another bridge (172.18.0.1/16). One of them is named container_B_1 (ip: 172.18.0.2)

By default, I cannot ping from container_A to container_B_1

The question: how to make that particular container (container_B_1) accessible as well from the default bridge network? In other words: to let it have 172.17.0.x IP (beside the 172.18.0.x IP). Just that one container.

I've tried this in my docker-compose.yml

enter image description here

But, gettting error: "Network-scoped alias is supported only for containers in user defined networks"

enter image description here

Thanks!


Solution

  • You could create your own network and specify it in your compose file:

    • Create your own network: docker network create --driver bridge my_dev_network you could verify by docker network ls

    • In your docker-compose.yml for the two containers (container A) and the other group of containers, specify the network you just created:

    network

    you could verify by docker network inspect my_dev_network to see if all the containers have joined your own network