1

Assuming the following docker-compose.yml:

version: '3'

services:
  db:
    image: postgres:12
    restart: always
    environment:
      - POSTGRES_USER=root
      - POSTGRES_PASSWORD=password
    volumes:
      - ./postgres:/docker-entrypoint-initdb.d/
    ports:
      - 5420:5420

With the knowledge of: How can I import a JSON file into PostgreSQL? to load data from a json file into Postgres... i.e:

sql> \set content `cat /tmp/test.json`
sql> create temp table t ( j jsonb );
sql> insert into t values (:'content');
sql> select * from t;

How do I ensure that I my initialize script can see the .json files when executing cat /tmp/test.json inside docker?

PeterCode
  • 11
  • 4
  • You either need to make sure the JSON file is visible in the container too (putting it in the `/docker-entrypoint-initdb.d` directory is file, the initialization only runs `*.sql` and `*.sh` files), or run the initialization script by hand from outside the container (the second `ports:` number needs to be the standard PostgreSQL port 5432). – David Maze Sep 14 '21 at 10:16

0 Answers0