1

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.

Maik Lowrey
  • 15,957
  • 6
  • 40
  • 79
  • Are you talking about MySQL or databases in general? – Hans Kilian Nov 17 '21 at 10:25
  • @HansKilian Good querstion. I talking about MySQL. I will updated my question. Thanks! – Maik Lowrey Nov 17 '21 at 10:27
  • I'm only familiar with `source` as a non-standard Bourne shell extension, that wouldn't be able to read SQL files. Is there a particular place you're running this? You seem familiar with the `docker-entrypoint-initdb.d` mechanism already; is there a more specific problem you're running into? – David Maze Nov 17 '21 at 12:13
  • @DavidMaze Thanks for your answer. source is a command within the mysql cli. source /path_to_dump.sql . Works quite well. I tried entrypoint but unfortunately it didn't work and I didn't get an error message. I am updating my question about this again. – Maik Lowrey Nov 17 '21 at 13:18

0 Answers0