Reputation: 21
I want to import a database that is saved on Windows into a PostgreSQL container on Docker.
After building and publishing the containers successfully, I run the Docker containers using docker-compose up –d
and then try to import the database into the project.
user@DESKTOP-A2MVLM4 MINGW64 ~/dockerProjectImage (master)
$ docker-compose exec db pg_restore -U fewo -h localhost --dbname=dbName backups/backup.psql
On Windows, I have the the following directory structure:
and now I try to import database backup.psql
from folder named backups
which has the backup.psql
file.
But I get an error:
user@DESKTOP-A2MVLM4 MINGW64 ~/dockerProjectImage (master)
$ docker-compose exec db pg_restore -U fewo -h localhost --dbname=dbName backups/backup.psql
pg_restore: [archiver] could not open input file "backups/backup.psql": No such file or directory
while the directory and file both are available.
docker-compose.yml:
version: '2'
services:
web:
image: image-url-web:latest
links:
- db
- memcached
- solr
ports:
- 8080:80
- 8443:443
volumes:
- ./:/var/www
solr:
image: image-url-solr:latest
links:
- db
ports:
- "8700:8700"
- "8710:8710"
- "8720:8720"
- "8730:8730"
restart: always
db:
image: image-url-db:latest
ports:
- "8032:5432"
restart: always
environment:
POSTGRES_DB: dbName
POSTGRES_USER: dbUser
POSTGRES_PASSWORD: 'password'
POSTGRES_INITDB_ARGS: '-E SQL_ASCII'
volumes:
- ./:/var/www/backups
memcached:
image: memcached:1.4.31
restart: always
Upvotes: 2
Views: 15766
Reputation: 56637
Per your screenshot, you have a backups
directory on your Windows system. It seems to be at the same level as the directory you are sitting in at the point you run your docker exec
command (based on the shell prompt in your example).
However, what matters is what is available inside the container. The command you run using docker exec
is running inside your container, not on your Windows system directly. The container in question here is the db
service, which has a volume mount defined in docker-compose.yml
:
db:
volumes:
- ./:/var/www/backups
This will mount the base directory (the one where docker-compose.yml
lives) at /var/www/backups
inside the container.
From your screenshot, I cannot tell where docker-compose.yml
lives, but your command text example suggests that it probably lives in ~/dockerProjectImage
. So that is the directory mounted at /var/www/backups
.
From that point, you cannot reach the backups
directory shown in your screenshot. It is outside of dockerProjectImage
, so it will not be part of the mount.
One way to fix this would be to move the backups
directory inside dockerProjectImage
. Then it would become available inside the container as /var/www/backups/backups/
. However, that still won't work the way you wrote your command (probably) because you are using a relative path (backups/backup.psql
). You would need to specify the full path, e.g.
docker-compose exec db pg_restore -U fewo -h localhost \
--dbname=dbName /var/www/backups/backups/backup.psql
Upvotes: 4