...
db:
command: mkdir db
image: mysql:5.7
container_name: mysql-db
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_ROOT_PASSWORD: "SECRET_root"
MYSQL_DATABASE: "db__docker"
MYSQL_USER: "user"
MYSQL_PASSWORD: "SECRET_user"
#MYSQL_HOST: 127.0.0.1
ports:
- 3308:3306
...
db:
command: mkdir db
image: mysql:5.7
container_name: mysql-db
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_ROOT_PASSWORD: "super_pass_root"
MYSQL_DATABASE: "db__docker"
MYSQL_USER: "user"
MYSQL_PASSWORD: "super_pass_for_user"
ports:
- 3318:3306
volumes:
- ./db:/var/lib/mysql
- ./file_setting/init.sql:/docker-entrypoint-initdb.d/init.sql
command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
When a container is started for the first time, a new database with the specified name will be created and initialized with the provided configuration variables. Furthermore, it will execute files with extensions .sh, .sql and .sql.gz that are found in /docker-entrypoint-initdb.d. Files will be executed in alphabetical order. You can easily populate your mysql services by mounting a SQL dump into that directory and provide custom images with contributed data. SQL files will be imported by default to the database specified by the MYSQL_DATABASE variable.
Furthermore, it will execute files with extensions .sh, .sql and .sql.gz that are found in /docker-entrypoint-initdb.d
.