0

I have created a docker-compose file with 2 services web and POSTGRES. When I run the below docker-compose file, it does not create tables that is in my local POSTGRES db. I have provided the environment variables to use. I think it should use these variables and grab the schema and creates the schema in docker right? When I call the rest API, I am getting relation "x" does not exist.

version: "3"
services:
  web:
    build: .
    depends_on:
      - postgres
    ports:
      - "8000:8000"
    volumes:
      - postgres-db:/var/lib/postgresql/data
    environment:
      - DATABASE_HOSTNAME=postgres
      - DATABASE_PORT=5432
      - DATABASE_PASSWORD=password!
      - DATABASE_NAME=dump
      - DATABASE_USERNAME=postgres
      - SECRET_KEY=021158d8d8d8d8d8d8d8d87
      - ALGORITHM=HS256
      - ACCESS_TOKEN_EXPIRE_MINUTES=50
  postgres:
    image: postgres
    environment:
      - POSTGRES_PASSWORD=password!
      - POSTGRES_DB=dump
volumes:
  postgres-db: {}

Ziv
  • 95
  • 7
  • Nothing you show here would cause the `postgres` container to create a schema or anything beyond an initial empty database. Do you need to mount content to the container's `/docker-entrypoint-initdb.d` directory, or set the application container to run migrations on startup? (It also looks like you're mounting the `postgres-db` volume into the wrong container, which could cause the database to lose data.) – David Maze Jan 27 '22 at 19:43
  • Whatever I have locally, I want those records to migrate. I have used python alembic to create schema. These are all in web service. I need to point docker to migrate these schemas somehow. – Ziv Jan 27 '22 at 19:51
  • That sounds like you need to either back up and restore your local database into the Docker database, or run your application's migrations against the Docker database. Docker on its own doesn't know how to do either of these things. Something like [How do you perform Django database migrations when using Docker-Compose?](https://stackoverflow.com/questions/33992867/how-do-you-perform-django-database-migrations-when-using-docker-compose) describes some common approaches. – David Maze Jan 27 '22 at 21:22

0 Answers0