2

I'm trying to query a CSV into a DB, but always returns the error (No such file or directory).

The file should be hosted on the /tmp folder on the container?

Database: postgres:13.2-alpine (Docker container)

Backend: node + slonik (on top of pg)

docker-compose.yml

version: '3.8'
services:
  db:
    image: postgres:13.2-alpine
    ports:
      - 5432:5432
    environment:
      POSTGRES_USER: <>
      POSTGRES_PASSWORD: <>
      POSTGRES_DB: <>

  db_admin:
    image: adminer
    ports:
      - 8080:8080
    depends_on:
      - db

Desired query:

\COPY rams(ram) FROM '/Users/…/rams.csv' WITH (FORMAT CSV) HEADER;

Error:

node:59682) UnhandledPromiseRejectionWarning: error: could not open file "/Users/…/rams.csv" for reading: No such file or directory

Best,

2
  • "The file should be hosted on the /tmp folder on the container?" Why is that a question? Either it is there, or it is not there. Your yml file certainly doesn't do anything to put it there. And your \copy also isn't looking for it there, unless that is through some unintuitive symlink. Commented Aug 24, 2022 at 23:42
  • <irony>brilliant answer</irony>. Now the user, who is classified as newbie, has no clear picture what to do. And will probably not use "our" service again. You didn't provide any help in your comment, or gave any direction where to lookup further info. At least s.th. on volumes and perhaps mounting and a docker link would have done the trick. This comment is useless. Commented Nov 24, 2022 at 13:40

1 Answer 1

5

There are several options to make connection between your local machine and a docker container, running the database. As already mentioned in my comment, looking up the section on volumes in docker documentation provides an overview. But this does not really fit, when you have an already running database container. This is what I do in such a case:

docker cp my_products.csv <database docker image>:/tmp

How do we get the "database docker image"? Simply by doing a docker ps (name is in the last column).

REFERENCE/CREDITS: https://dev.to/adron/getting-copy-for-bulk-csv-working-on-a-container-running-postgresql-3kk9

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.