2
I have the following file Docker-Compose.yml:
version: "3.3"
services:
mysql:
container_name: mysql
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: senha_root
MYSQL_DATABASE: database_name
command: ['--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci']
volumes:
- ./mysql/tmp:/var/lib/mysql
restart: always
ports:
- 3306:3306
web:
container_name: web
image: web_dev
build:
context: .
dockerfile: Dockerfile-web
volumes:
- ./projeto/:/var/www
- ./apache/:/etc/apache2/sites-enabled/
working_dir: /var/www
depends_on:
- mysql
links:
- mysql
restart: always
ports:
- 80:80
- 3000:3000
- 3001:3001
Reading some posts I noticed that it is usually added instruction Networks, getting this way:
version: "3.3"
services:
mysql:
container_name: mysql
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: senha_root
MYSQL_DATABASE: database_name
command: ['--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci']
networks:
- dev
volumes:
- ./mysql/tmp:/var/lib/mysql
restart: always
ports:
- 3306:3306
web:
container_name: web
image: web_dev
build:
context: .
dockerfile: Dockerfile-web
volumes:
- ./projeto/:/var/www
- ./apache/:/etc/apache2/sites-enabled/
working_dir: /var/www
networks:
- dev
depends_on:
- mysql
links:
- mysql
restart: always
ports:
- 80:80
- 3000:3000
- 3001:3001
networks:
dev:
From what I could understand, when declaring the Networks instruction as above, I am creating a new network interface, however, I did not understand what the real explanation and necessity of this, some explanation?
And for what reason usually repeats the word network at the end of the file, this is to expose the network?
Ball show. That explanation took away the doubt I had. Thank you.
– Fábio Jânio