A
A
Anton Shvets2016-07-13 10:35:11
Computer networks
Anton Shvets, 2016-07-13 10:35:11

How to set up a container network with docker-compose?

There are a number of services in different folders, each of them has its own compose file.
Running docker-compose up creates two separate networks, br-xxxxxxxxxxxx and vethxxxxxx, from which the services described in the compose file get addresses. (It would be nice to cut out the veth that I don't need)
Ie . how many compose files, so many networks are created.
I would like to organize only one network for containers so that they see each other and address each other by name.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel, 2016-07-13
@Xuxicheta

I use docker-compose file version 2
Manually create
network Add network description to each file

networks:
  mynetwork:
    external:
      name: myglobalnetwork

We set aliases for services for networks through which containers will communicate
services:
  nginx:
    build: ./nginx
    networks:
      mynetwork:
        aliases:
          - nginx.mynetwork
  postgres:
    build: ./postgres
    networks:
      mynetwork:
        aliases:
          - postgres.mynetwork

Here nginx.mynetwork and postgres.mynetwork are the internal dns addresses of the containers

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question