I am currently aware of two ways to get an existing MySQL database into a database Docker container. docker-entrypoint-initdb.d
and source /dumps/dump.sql
. I am new to dockering and would like to know if there are any differences between the two approaches. Or are there special use cases where one or the other approach is used? Thank you!
Update
How i use source:
In my docker-compose.yml file i have this few lines:
mysql:
image: mysql:5.7
container_name: laravel-2021-mysql
volumes:
- db_data:/var/lib/mysql
- ./logs/mysql:/var/log/mysql
- ./dumps/:/home/dumps # <--- this is for the dump
docker exec -it my_mysql bash
then
mysql -uroot -p
then
create DATABASE newDB;
then
use newDB;
then
source /home/dumps/dump.sql
How i use docker-entrypoint-initdb.d:
But it not works. On my host i create the folder dumps and put this dump.sql in it.
My docker-compose.yml file:
mysql:
image: mysql:5.7
container_name: laravel-2021-mysql
volumes:
- db_data:/var/lib/mysql
- ./logs/mysql:/var/log/mysql
- ./dumps/:/docker-entrypoint-initdb.d
Then: docker-compose up
. But I can't find the dump in my database. I must be doing something wrong.