Docker Compose mysql import .sql

前端 未结 5 704
伪装坚强ぢ
伪装坚强ぢ 2021-01-31 16:32

I\'m having trouble importing an .sql dump file with docker-compose. I\'ve followed the docs, which apparently will load the .sql file from docker-entrypoint-initdb.d. However,

5条回答
  •  执笔经年
    2021-01-31 16:53

    After many attempts with the volumes setting i found a workaround

    I created another image based on mysql with the following in the Dockerfile

    FROM mysql:5.6
    
    ADD dump.sql /docker-entrypoint-initdb.d
    

    Then removed the volumes from compose and ran the new image

    frontend:
      image: myimage
      ports:
       - "80:80"
      links:
       - mysql
    mysql:
      image: mymysql
      ports:
       - "3306:3306"
      environment:
        MYSQL_ROOT_PASSWORD: rootpass
        MYSQL_USER: dbuser
        MYSQL_PASSWORD: userpass
        MYSQL_DATABASE: myimage_db
    

    This way the dump is always copied over and run on startup

提交回复
热议问题