Docker 使用 docker-compose 安装 MySQL 5.7

一、创建映射目录

mkdir -p /root/software/mysql5.7/data
mkdir -p /root/software/mysql5.7/conf/conf.d
mkdir -p /root/software/mysql5.7/logs

二、创建 docker-compose.yml

version: '3'
services:
  mysql:
    image: mysql:5.7
    container_name: mysql
    command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
    restart: always
    network_mode: bridge
    environment:
      MYSQL_ROOT_PASSWORD: 123456
    ports:
      - 3306:3306
    volumes:
      - /root/software/mysql5.7/data:/var/lib/mysql
      - /root/software/mysql5.7/conf/conf.d:/etc/mysql/conf.d
      - /root/software/mysql5.7/logs:/var/log/mysql
    deploy:
      mode: global
      resources:
        limits:
          memory: 2048M

三、部署

docker-compose up -d

四、常用命令

# 删除容器(参数可以是容器名称或容器ID)
docker rm mysql
# 删除镜像
docker rmi mysql
# 启动容器
docker start mysql
# 启动容器/重启容器
docker restart mysql
# 停止容器
docker stop mysql
# 进入容器
docker exec -it mysql bash

你可能感兴趣的:(Docker,mysql,docker,数据库)