Docker Compose
Docker Compose uses a docker-compose.yml
file to link several containers and achieve fast deployment of a porject with multiple containers.
Example of docker-compose.yml
version: "3.8" # version of yml syntax
services:
containerA:
image: mysql
container_name: mysql2
ports:
- "3306:3306"
environment:
TZ: Asia/Shanghai
MYSQL_ROOT_PASSWORD: 123
volumes:
- "./mysql/conf:/etc/mysql/conf.d"
networks:
- myNetwork
containerB:
build:
context: .
dockerfile: Dockerfile
container_name: hmall
ports:
- "8080:8080"
depends_on:
- mysql2
networks:
- myNetwork
# ...
networks:
myNetwork: # the tag of the network in this yml file
name: my-network # the real name of the network created
docker compose
Commands
docker compose [OPTIONS] [COMMAND]
options:
-f
: specify the path of the compose file-p
: specify the project name-d
: run in background
commands:
up
: create and launch all containersdown
: stop and remove all containers and networkps
: list all launched containerslogs
: check a container's logsstop
: stop a containerstart
: start a containerrestart
: restart a containertop
: check running containersexec
: execute commands in a specified container
To get help, use --help
option