步骤1:
安装docker与docker-compose
#!/bin/bash echo "开始安装 docker" sudo yum install -y yum-utils sudo yum-config-manager \ --add-repo \ https://download.docker.com/linux/centos/docker-ce.repo sudo yum install -y docker-ce docker-ce-cli containerd.io sudo systemctl enable docker sudo systemctl start docker #echo "拉取 hello-world 仓库" # sudo docker run hello-world #echo "设置阿里云源" #sudo yum-config-manager \ # --add-repo \ # http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo docker --version echo "开始安装 docker-compose " sudo curl -L "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose docker-compose --version
步骤2:
编写docker-compose.yaml文件
version: "3" services: mysql: container_name: mysql environment: - MYSQL_ROOT_PASSWORD=123456 image: mysql:8.0.16 logging: driver: json-file options: max-size: "1g" ports: - 3306:3306/tcp restart: always command: --default-authentication-plugin=mysql_native_password volumes: - /home/data/mysql:/var/lib/mysql - /home/data/config/my.cnf:/etc/mysql/my.cnf
步骤3:
编写好my.cnf文件与创建数据库映射目录
在docker-compose.yaml当前目录执行docker-compose up -d