Doubts about communication between containers

Asked

Viewed 1,182 times

0

I have a question about the communication between containers, in my Docker-Compose I am creating a link between the container web and mysql. This link would be an internal network?

If not, it would 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
  • It is not the same doubt as yours, but I answered something in this sense here, about the networks in a Compose: https://answall.com/questions/243881/docker-compose-link/243957#243957

  • I didn’t understand it very well. This instruction Links that I used, does exactly what?

1 answer

1


The link simply represents an entry into the HOSTS of your container. As the link information goes to the container metadata, whenever you go up this container Docker discovers the correct IP of the "linked" container and hits the HOSTS file of the container that depends on the link. This process makes your container not need to resolve the name on an IP, it simply "knows".

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

You can inspect your networks using the docker network, as docker network ls for example..

  • Another interesting point is that you can see this metadata, using the docker inspect [containerName]

  • is there a difference in performance between these approaches? For example, it would be more performative to add these containers to a virtual network?

  • 1

    I can’t answer that. I’ve never found anything that would make that counterpoint. Until pq I think we are talking about the same implementation, which would have similar performance.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.