docker-compose.yml

version: '3.3'
services:
  db:
    image: mysql:5.7
    privileged: true
    restart: always
    command: mysqld  --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --explicit_defaults_for_timestamp=true --lower_case_table_names=1 --max_allowed_packet=128M  --sql-mode="STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
    environment:
      MYSQL_DATABASE: 'db'
      MYSQL_USER: 'root'
      MYSQL_PASSWORD: 'mysql123456'
      MYSQL_ROOT_PASSWORD: 'mysql123456'
    ports:
      - '3306:3306'
    expose:
      - '3306'
    volumes:
      - /data/docker/mysql:/var/lib/mysql

privileged: true

因为没有root权限此命令可设置容器为特例容器 :

外挂盘:

volumes: 
      - /data/docker/mysql:/var/lib/mysql

指定字符集:

command: [
      '--character-set-server=utf8mb4',
      '--collation-server=utf8mb4_unicode_ci',:
    ]

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐