1. mysql 5.7

docker-compose.yml

version: '3'
services:
  app:
      image: mysql:5.7
      container_name: mysql
      restart: on-failure:3
      command:
        - --default-authentication-plugin=mysql_native_password
        - --character-set-server=utf8mb4
        - --collation-server=utf8mb4_general_ci
        - --explicit_defaults_for_timestamp=true
      volumes:
        - ./data:/var/lib/mysql
#        - ./conf:/etc/mysql
        - ./mysqlBackup:/data/mysqlBackup
      ports:
        - "3306:3306"
      healthcheck:
        test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "--silent"]
        interval: 3s
        retries: 5
        start_period: 30s
      environment:
        - MYSQL_ROOT_PASSWORD=root
networks:
  default:
    driver: bridge
  1. mysql 8

docker-compose.yml

version: '3'
services:
  app:
      image: mysql:8.0.31
      container_name: mysql8
      restart: on-failure:3
      command:
        - --default-authentication-plugin=mysql_native_password
        - --character-set-server=utf8mb4
        - --collation-server=utf8mb4_general_ci
        - --explicit_defaults_for_timestamp=true
      volumes:
        - ./data:/var/lib/mysql
#        - ./conf:/etc/mysql
        - ./mysqlBackup:/data/mysqlBackup
      ports:
        - "3306:3306"
      healthcheck:
        test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "--silent"]
        interval: 3s
        retries: 5
        start_period: 30s
      environment:
        - MYSQL_ROOT_PASSWORD=root
networks:
  default:
    driver: bridge