I would like to load data from CSV file into PostgreSQL database in Docker. I run:
docker exec -ti my project_db_1 psql -U postgres
Then I select my database:
\c myDatabase
Now I try to load data from myfile.csv which is in the main directory of the Django project into backend_data table:
\copy backend_data (t, sth1, sth2) FROM 'myfile.csv' CSV HEADER;
However I get error:
myfile.csv: No such file or directory
It seems to me that I tried every possible path and nothing works. Any ideas how can I solve it? This is my docker-compose.yml:
version: '3'
services:
db:
image: postgres
environment:
POSTGRES_USER: myuser
POSTGRES_PASSWORD: mypassword
django:
build: .
command: python3 manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- "8000:8000"
depends_on:
- db
myfile.csvin,djangoordb? Which container are you exec'ing into?djangoordb?myfile.csvis in main directory where is alsodocker-compose.ymlandDockerfileof Django project. I execute\copy backend_data (t, sth1, sth2) FROM 'myfile.csv' CSV HEADER;inproject_db_1.dbcontainer, the filemyfile.csvis not in thedbcontainer, and you are running the command in that container. Possible solution add in docker-compose.ymlvolumes: - "<path_to_csv_in_local>:<path_to_csv_in_db_container>"