简体   繁体   English

如何使用卷从 docker 中的转储或 sql 文件中恢复数据库?

[英]How to restore database from dump or sql file in docker using volume?

I am trying to run my database in docker which already have some data into it, But when I run it in docker it gives empty.. So how to restore my database in docker PostgreSQL image. I am trying to run my database in docker which already have some data into it, But when I run it in docker it gives empty.. So how to restore my database in docker PostgreSQL image.

First, Start your docker posgtres container.首先,启动您的 docker posgtres 容器。 Then execute the following command:然后执行以下命令:

docker exec -i <CONTAINER> -U <USER> -d <DB-NAME> < <PATH-TO-DUMP>

  • <CONTAINER> : Container ID or container name <CONTAINER> : 容器 ID 或容器名称
  • <USER> : User of PostgreSQL DBMS. <USER> : PostgreSQL DBMS 的用户。 If you use the standard postgres image with no specific config the user is postgres如果您使用没有特定配置的标准 postgres 图像,则用户是postgres
  • <DB-NAME> : The name of the DB. <DB-NAME> :数据库的名称。 This DB should already exist.该数据库应该已经存在。 You can create a db when running your postgres container by specifying an environment variable named POSTGRES_DB您可以通过指定名为POSTGRES_DB的环境变量在运行 postgres 容器时创建数据库
  • <PATH-TO-DUMP> : Specify here the path to your dump file <PATH-TO-DUMP> :在此处指定转储文件的路径

Example: docker exec -i mypostgres psql -U postgres -d mydb < backup.sql示例: docker exec -i mypostgres psql -U postgres -d mydb < backup.sql

Hope this helps.希望这可以帮助。

I am getting this error, when I dockerize Pdi Jobs.当我对 Pdi Jobs 进行 dockerize 处理时,我收到了这个错误。

ERROR (version 8.3.0.0-371, build 8.3.0.0-371 from 2019-06-11 11.09.08 by buildguy): An error occurred, processing will be stopped: 2019/10/31 05:02:03 - Table input.0 - Error occurred while trying to connect to the database 2019/10/31 05:02:03 - Table input.0 - 2019/10/31 05:02:03 - Table input.0 - Error connecting to database: (using class org.postgresql.Driver) 2019/10/31 05:02:03 - Table input.0 - Connection to localhost:5432 refused.错误(版本 8.3.0.0-371,buildguy 从 2019-06-11 11.09.08 构建 8.3.0.0-371):发生错误,处理将停止:2019/10/31 05:02:03 - 表输入.0 - 尝试连接到数据库时发生错误 2019/10/31 05:02:03 - 表 input.0 - 2019/10/31 05:02:03 - 表 input.0 - 连接到数据库时出错:(使用 class org.postgresql.Driver) 2019/10/31 05:02:03 - 表 input.0 - 连接到 localhost:5432 被拒绝。 Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.检查主机名和端口是否正确以及 postmaster 是否接受 TCP/IP 连接。 2019/10/31 05:02:03 - Table output.0 - ERROR (version 8.3.0.0-371, build 8.3.0.0-371 from 2019-06-11 11.09.08 by buildguy): An error occurred intialising this step: 2019/10/31 05:02:03 - 表 output.0 - 错误(版本 8.3.0.0-371,buildguy 从 2019-06-11 11.09.08 开始构建 8.3.0.0-371):初始化此步骤时发生错误:

My docker-compose File:我的 docker-compose 文件:

version: '3.1'版本:'3.1'

services: pdijobs: image: pdijobs restart: always build: context: .服务:pdijobs:图像:pdijobs 重新启动:始终构建:上下文:。 dockerfile: Dockerfile dockerfile:Dockerfile

volumes:
- ./data/jasper-data:/usr/local/tomcat/webapps
ports:
  - "8080:8080"
depends_on:
  - datawarehouse-db
environment:
  DB_TYPE: postgresql
  DB_HOST: datawarehouse-db
  DB_NAME: data-warehouse
  DB_USER: postgres
  DB_PASSWORD: admin

datawarehouse-db: image: postgres:10 restart: "no" environment: POSTGRES_DB: data-warehouse POSTGRES_USER: postgres POSTGRES_PASSWORD: admin datawarehouse-db: image: postgres:10 restart: "no" environment: POSTGRES_DB: data-warehouse POSTGRES_USER: postgres POSTGRES_PASSWORD: admin

volumes: postgres-data: pgdata:卷:postgres 数据:pgdata:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM