0

I'm having trouble importing an .sql dump file with docker-compose. With docker-entrypoint-initdb.d I should be able to load the .sql file... .However, when I run docker-compose up, the sql file is not copied over to the container.

What am I doing wrong in my .yml script?

I have init.sql in the directory in the root directory where my compose file is.

Furthermore I the database but not the data (tables, inserts, more) are on adminer :(

version: '3'

services:

  mysql-dev:
    image: mysql:8.0.2
    #command: --default-authentication-plugin=mysql_native_password
    restart: always
    environment: 
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: sdaapp
    ports: 
      - "3308:3306"
    volumes: 
      - "./data:/var/lib/mysql:rw"
      - "./init:/docker-enttrypoint-initdb.d"

  pgdb-dev:
    image: postgres
    restart: always
    environment:
      POSTGRES_USER: root
      POSTGRES_PASSWORD: password
      POSTGRES_DB: sdaapp
  
  admin:
    build:
      context: .
      dockerfile: Dockerfile
    image: adminer
    restart: always
    ports:
      - 8080:8080

THANKS for your help :)

  • 1
    check this [post](https://stackoverflow.com/questions/43880026/import-data-sql-mysql-docker-container) – Chandan Jan 07 '21 at 16:23
  • Does this answer your question? [Import data.sql MySQL Docker Container](https://stackoverflow.com/questions/43880026/import-data-sql-mysql-docker-container) – L.Lauenburg Jan 07 '21 at 18:54

1 Answers1

0

Since your volume is pointed to ./init folder, you have to put your .sql script inside of it (or change the path of your volume). Also note that there is a typo in your docker-compose.yml file: docker-enttrypoint-initdb.d should be docker-entrypoint-initdb.d

And as pointed by MySQL's Documentation, the script is executed only for the first time you run the container. So you have to delete the database before running the container again and then be able to execute the script correctly.

vpalmerini
  • 403
  • 4
  • 9
  • in case that mysql data is persisted to a volume, and dump import fails the first time, check this answer: https://stackoverflow.com/questions/59958574/why-isnt-force-recreate-rebuilding-my-docker-mysql-image – funder7 Jun 12 '21 at 20:01