Doug Smith
Doug Smith

Reputation: 580

How to use pg_restore with docker on windows?

I am using docker-compose on my windows computer. I start up two containers, one web and one db. I would like to use pg_restore to import a dump file I created. docker-compose.yaml

version: '3.8'

services:
  web:
    build: .
    command: python /code/manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/code
    ports:
      - 8000:8000
    stdin_open: true
    tty: true
    depends_on:
      - db
    environment:
      - "DJANGO_SECRET_KEY=django-insecure-rt@&+(5fp=+$$hj87no^w40l&d-q6wk5b3jdvos_=kt#@+85b8f"
      - "DJANGO_DEBUG=True"
      - "ALLOWED_HOSTS=172.105.16.56,.smartmark.ca,localhost,127.0.0.1"

  db:
    image: postgres:11
    volumes:
      - postgres_data:/var/lib/postgresql/data/
    environment:
      - "POSTGRES_HOST_AUTH_METHOD=trust"

volumes:
  postgres_data:

I thought I could use this:

docker-compose exec smartmark-db-1 pg_restore -U postgres -d postgres export.dbase

When I do this, I get an error service "smartmark-db-1" is not running container #1.

docker ps gives me container ID and container name = e38c4e72db25 smarmark-db-1

I have also seen other answers which say to use code like below:

docker exec -i container_name pg_restore -Fc -U admin_username -d database_name < pg_dump_Fc_file

But in windows command, we get an error with the <.

The '<' operator is reserved for future use.

Upvotes: 0

Views: 202

Answers (1)

Ismael
Ismael

Reputation: 11

You can install pg_restore on your windows machine and then connect it to the db. However you need to expose the db container port to the host (let's assume its 5432)

pg_restore -Fc -U admin_username -d database_name -h localhost -p 5432 pg_dump_Fc_file

Upvotes: 0

Related Questions