我正在尝试将.backup
文件还原到Postgresql数据库。为此,我使用docker-compose文件启动postgres docker容器:
docker-compose.yml
postgresql: image: postgres restart: always ports: - "5432:5432" environment: - POSTGRES_USER:postgres # - PGDATA:/var/lib/postgresql/data/pgdata/ volumes: - ${PWD}/project/data/MX/bkup/data:/var/lib/postgresql command: - pg_restore -U postgres -d postgres /var/lib/postgresql/ph.backup
当我使用以下命令运行docker-compose文件时:
docker-compose up postgresql
我收到错误:
postgresql: image: postgres restart: always ports: - "5432:5432" environment: - POSTGRES_USER:postgres # - PGDATA:/var/lib/postgresql/data/pgdata/ volumes: - ${PWD}/project/data/MX/bkup/data:/var/lib/postgresql command: - pg_restore -U postgres -d postgres /var/lib/postgresql/ph.backup
即使文件在卷中,也会发生这种情况
(virtual) med@nid:~/projects/project/pkg$ docker-compose up postgresql
Recreating pkg_postgresql_1 ...
Recreating pkg_postgresql_1 ... done
Attaching to pkg_postgresql_1
postgresql_1 | /usr/local/bin/docker-entrypoint.sh: line 176: /pg_restore -U postgres -d postgres /var/lib/postgresql/ph.backup: No such file or directory
pkg_postgresql_1 exited with code 127
我试图在docker-compose命令中使用-h
参数pg_restore
:
pg_restore -h tcp://`docker-machine ip default`:5432 -U postgres -d postgres /var/lib/postgresql/ph.backup
可行的方法:如果我在中注释了命令目标docker-compose.yml
,请启动docker容器并在其中运行命令,然后注入数据!
有没有解决的办法,意思是,有没有办法使命令直接从docker-compose.yml
文件中起作用?