Access sql dump inside docker container django postgres

Issue

I’m using Django with Postgres database so I’ve created separate docker containers for Django and Postgres, now I want to share the dump file with my team but I’m unable to access the dump file, please let me know how can I access the dump file and after accessing it how can we import it using the container?

docker-compose.yml

version: "3.8"
   
services:
  pgdb:
    image: "postgres"
    restart: always
    volumes:
      - postgres_data:/var/lib/postgresql/data/
    ports:
      - "5432:5432"

location inside db docker container

enter image description here

Solution

You can access it using docker cp utility

docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|-

But rather than doing that you can directly pipe output of pg_dump

docker exec -t container pg_dump ... > dump.sql

and import

cat dump.sql | docker exec -i container psql ...

Answered By – iklinac

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published