一、文件结构
data #挂载的文件夹对应mysql/data
log #日志文件夹
docker-compose.yml 创建容器脚本
结构图如下:
二、创建docker-compose.yml 脚本
version: "3.7"
services:
mysql:
image: mysql:8.0
restart: always
container_name: mysql
environment:
MYSQL_ROOT_PASSWORD: "root" # root密码
MYSQL_USER: newuser # 新用户账号
MYSQL_PASSWORD: newpass # 新用户 密码
ports:
- 33060:3306
volumes:
- ./data:/var/lib/mysql
- ./log:/var/log/mysql
networks:
- public #网桥 这里的网桥名称“public” 可以当前这行和下面下面networks删除,用系统默认的
networks:
public: #对应“public网桥”
external: true
ps:自定义网桥
# 查询docker 网桥
docker network ls
#显示
# docker network ls
NETWORK ID NAME DRIVER SCOPE
9afd996ab277 bridge bridge local
af262c1aa186 host host local
6b9b2b8e846f none null local
# 创建名字为 “public” 网桥
docker network create --subnet=172.18.0.0/16 public
#再次查看
docker network ls
#显示
# docker network ls
NETWORK ID NAME DRIVER SCOPE
9afd996ab277 bridge bridge local
af262c1aa186 host host local
6b9b2b8e846f none null local
44620d229733 public bridge local