1.安装Compose
#yum安装
yum install docker-compose -y
#下载地址:https://pan.baidu.com/s/16Q34M0z3w7Wlbf_8EgWB3Q 提取码:qtm1
mv docker-compose-Linux-x86_64 /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
2.创建docker-compose.yml
version: '2'
services:
dkn-mysql:
environment:
MYSQL_ROOT_PASSWORD: root
restart: always
container_name: dkn-mysql
image: docker.io/mysql:8.0.20
ports:
- 3306:3306
dkn-redis:
image: redis:6.0
ports:
- 6379:6379
restart: always
container_name: dkn-redis
hostname: dkn-redis
2.构建并启动运行
# 构建镜像
docker-compose build
# 启动服务
docker-compose up -d
# 停止服务
docker-compose down --rmi all -v
# 查看日志
docker-compose logs -f