docker-部署 Mysql (docker-compose)

使用 docker-compose 部署 mysql

 

一、安装 docker-compose

安装教程:https://blog.csdn.net/W_Meng_H/article/details/106208422

 

二、mysql 的 docker-compose 文件

version: '3.1'
services:
  mysql:
    restart: always
    image: mysql:5.7.22
    container_name: mysql
    ports:
      - 3306:3306
    environment:
      TZ: Asia/Shanghai
      MYSQL_ROOT_PASSWORD: 123456
    command:
      --character-set-server=utf8mb4
      --collation-server=utf8mb4_general_ci
      --explicit_defaults_for_timestamp=true
      --lower_case_table_names=1
      --max_allowed_packet=128M
      --sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO"
    volumes:
      - /usr/local/docker/mysql/conf:/etc/mysql
      - /usr/local/docker/mysql/logs:/var/log/mysql
      - /usr/local/docker/mysql/data:/var/lib/mysql

 

三、启动 mysql

到 docker-compose.yml 文件夹下,使用 docker-compose 相关命令:

1、前台运行

docker-compose up

2、后台运行

docker-compose up -d

3、启动

docker-compose start mysql

4、重启

docker-compose restart mysql

5、停止

docker-compose stop mysql

6、停止并移除容器

docker-compose down mysql

 

 

你可能感兴趣的:(Docker)