yish8213
3/23/2017 - 10:05 AM

initialize MySQL database by init SQL file. init.sql can load only first time launching.

initialize MySQL database by init SQL file. init.sql can load only first time launching.

version: '3.1'

services:
   mysql:
     image: mysql:latest
     volumes:
       - db_data:/var/lib/mysql
       - /path/to/init.sql:/docker-entrypoint-initdb.d/init.sql
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: root
       MYSQL_DATABASE: test_db
       MYSQL_USER: test_user
       MYSQL_PASSWORD: test_pw
       MYSQL_CHARSET: utf8
       MYSQL_DATABASE_CHARSET: utf8
     ports:
       - "3306:3306"

volumes:
    db_data: