Doubts the communication between containers

0

I have a question about container communication, in my docker-compose I am creating a link between the web and mysql container. Would this link be an internal network?

If not, would it be more performative to create an internal network?

docker-compose.yml

version: "3.3"
services:
  mysql:
    container_name: mysql
    image: mysql:5.7
    environment:
      MYSQL_ROOT_PASSWORD: SENHA
      MYSQL_DATABASE: webApp
      MYSQL_USER: root
      MYSQL_PASSWORD: senha
    restart: always
    ports:
      - 3306:3306

  web:
    container_name: web
    image: web_dev
    build:
      context: .
      dockerfile: Dockerfile-web
    volumes:
      - ../Desenvolvimento Web/:/var/www
      - ./Apache/:/etc/apache2/sites-enabled/
    working_dir: /var/www
    depends_on:
      - mysql
    links:
      - mysql
    restart: always
    ports:
      - 80:80
    
asked by anonymous 07.10.2017 / 16:08

1 answer

1

The link simply represents an entry in the HOSTS of your container. As the link information goes to the container metadata, whenever you go up that container, docker finds the correct IP of the "linked" container and hits the HOSTS file of the container that depends on the link. This process causes your container not to resolve the name on an IP, it simply "knows".

A network in docker is literally a virtual network. The bridge network, for example, (except for default) does name resolution automatically, which means that instead of the container simply knowing what the IP is, it is the network drive that responds with the current information.

You can inspect your networks using the subcommands of docker network , like docker network ls for example ..

    
09.10.2017 / 10:32