I am migrating my project to the Docker. It has several components (server, mobile client, database, ethereum private chain) where each of them is planned to be run in a separate container.
For such aim I use docker compose. At this moment I am working on to run mysql database in the single container:
version: '3.8'
services:
database:
container_name: swap-database-default
image: mysql:8.0.33
environment:
- "MYSQL_ROOT_PASSWORD=secret"
- "MYSQL_DATABASE=homestead"
- "MYSQL_USER=homestead"
- "MYSQL_PASSWORD=secret"
- "MYSQL_ROOT_HOST=127.0.0.1"
volumes:
- ./infrastructure/mysql:/var/lib/mysql
- ./server/db_schema:/docker-entrypoint-initdb.d:rw
ports:
- "3307:3306"
This script is able to run mysql in a separate container and even create defined database (homestead), but it fails to execute schema shared with it.
$docker inspect swap-database-default | grep Gateway
$mysql -h 172.24.0.1 -P 3307 --protocol=tcp -u homestead -p
$ (mysql) show databases;
The last command is the last code block shows only homestead database, but does not show another two which schema.sql files have been shared within /infrastructure/mysql folder.
Somewhere in docs it was told every *.sql script within docker-entrypoint-initdb.d is run over container startup and this is ./server/db_schema:/docker-entrypoint-initdb.d
a right way to share this scripts within it.
My environment is:
Ubuntu 22.04.2 LTS
Docker version 23.0.4, build f480fb1
schema sql script
Does anyone know the root cause of this issue?