Search code examples
postgresqldockerdocker-volume

Dockerized PGAdmin Mapped volume + COPY not working


I have a scenario where a certain data set comes from a CSV and I need to allow a non-dev to hit PG Admin and update this data set. I want to be able to put this CSV in a mapped folder from the host system and then use the PG Admin GUI to run a COPY command. So far PG Admin is telling me:

ERROR: could not open file "/var/lib/pgadmin/data-files/some_data.csv" for reading: No such file or directory

Here are my steps so far, along with a sanity check inspect:

docker volume create --name=data-files

docker run -e PGADMIN_DEFAULT_EMAIL="[email protected]" -e PGADMIN_DEFAULT_PASSWORD=some_pass -v data-files:/var/lib/pgadmin/data-files -d -p 5050:80 --name pgadmin dpage/pgadmin4

docker volume inspect data-files  --format '{{.Mountpoint}}'
/app/docker/volumes/data-files/_data

docker cp ./updated-data.csv pgadmin:/var/lib/pgadmin/data-files

And, now I think that PG Admin could see the updated-data.csv, so I try COPY, which I know works locally on my dev system where PG Admin is on baremetal:

COPY foo.bar(
    ...
)
FROM '/var/lib/pgadmin/data-files/updated-data.csv'
DELIMITER ','
CSV HEADER
ENCODING 'windows-1252';

Is there any glaring mistake here? When I do docker cp there's no feedback to stdout. No error, no mention of success or a hash or anything.


Solution

  • It looks like you thought the file should be inside the pgadmin container however the file you are going to copy must be inside the postgres container so the query you run will find the file. I suggest you copy the file to postgres container :

    docker cp <path_from_your_local>/file.csv <postgres_container_name>:/file.csv
    

    Then in the query tool from your pgadmin you can copy without problems !

    I hope this help to others came here...