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 usually the networks statement is added, thus:
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:
As I could understand, by declaring the networks statement as above, I am creating a new network interface, however, I did not understand what the actual explanation and need is, some explanation?
And for what reason do you usually repeat the word network at the end of the file, is this to expose the network?