Categories
Docker postgres

Postgres docker import data

To load a csv file into a table, one way to do it is to use the docker cp command to copy the file into the container. You can then run the \copy command from a cmd line in the container.

docker cp ./projects.csv  some-postgres:/projects.csv
docker exec -it some-postgres psql -U postgres
** from psql:
postgres=# \copy projects(id,project_name,description) from '/projects.csv' csv header;

Categories
Docker postgres

docker and postgres sql

Back to fedora.  up to 31.
loading a sql file into a docker postgres db from the command line.
(see my github docker-compose for the postgres db setup)
note:
/data/raw is my shared volume with postgres;
some-postgres is the postgres container name
data2.sql is a sql txt file.


sudo docker exec -it  some-postgres psql  -U postgres  -d sqldb -f /data/raw/data2.sql