【问题标题】:How can I import a dump sql file -DOCKER如何导入转储 sql 文件 -DOCKER
【发布时间】:2021-01-07 16:08:44
【问题描述】:

我在使用 docker-compose 导入 .sql 转储文件时遇到问题。 使用 docker-entrypoint-initdb.d 我应该能够加载 .sql 文件... .但是,当我运行 docker-compose up 时,不会将 sql 文件复制到容器中。

我在 .yml 脚本中做错了什么?

我的 compose 文件所在的根目录中的目录中有 init.sql。

此外,我的数据库而不是数据(表,插入,更多)在管理员上:(

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

感谢您的帮助:)

【问题讨论】:

标签: mysql database docker docker-compose dockerfile


【解决方案1】:

由于您的卷指向./init 文件夹,您必须将.sql 脚本放入其中(或更改volume 的路径)。另请注意,您的docker-compose.yml 文件中有错字:docker-enttrypoint-initdb.d 应为docker-entrypoint-initdb.d

正如MySQL's Documentation 所指出的,该脚本仅在您第一次运行容器时执行。所以你必须在再次运行容器之前删除数据库,然后才能正确执行脚本。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2021-12-12
  • 2021-04-11
  • 2019-02-03
  • 2015-09-14
  • 1970-01-01
  • 1970-01-01
  • 2016-10-16
  • 2017-06-25
相关资源
最近更新 更多