The YAML file of Docker Compose contains 4 first-level keys: version, services, networks, volumes
-
version is mandatory and is always the first line in the file. It defines the version of the Compose file format (mainly the API). Note that version does not define the version number of Docker Compose or Docker Engine.
-
services are used to define different application services. The above example defines two services: a database service named lagou-mysql and a microservice named lagou-eureka. Docker Compose will deploy each service in its own container.
-
networks is used to instruct Docker to create new networks. By default, Docker Compose creates bridge networks. This is a single-host network that only enables connections to containers on the same host. Of course, you can also use the driver attribute to specify different network types.
-
volumes is used to instruct Docker to create new volumes.
version: '3'
services:
mysql:
build:
context: ./mysql
environment:
MYSQL_ROOT_PASSWORD: admin
restart: always
container_name: mysql
volumes:
- /data/edu-bom/mysql/test:/var/lib/mysql
image: mysql/mysql:5.7
ports:
- 3306:3306
networks:
net:
eureka:
build:
context: ./edu-eureka-boot
restart: always
ports:
- 8761:8761
container_name: edu-eureka-boot
hostname: edu-eureka-boot
image: edu/edu-eureka-boot:1.0
depends_on:
- mysql
networks:
net:
networks:
net:
volumes:
vol: