Unable to do migrations using docker.yml file- django+postgres

  django, docker, postgresql

I get the following error while I try to run my django project on docker.

relation "DBTable" does not exist at character 218

I figured out it was because the migrations weren’t being applied.
So I changed my Dockerfile as follows to make migrations before starting the server:

FROM python:3.7
WORKDIR /ServerCode2/
COPY . /ServerCode2/
RUN pip install -r req.txt
EXPOSE 8000
CMD ["python", "manage.py", "makemigrations" ]
CMD ["python", "manage.py", "migrate" ]
CMD ["python", "manage.py", "runserver", "--noreload" ]

Below is my docker-compose.yml file

version: '3.7'
services:
  server:
    build:
      context: ./Appname
      dockerfile: Dockerfile
    image: serverimgtest1
    container_name: servercontest1
    ports:
      - 8000:8000
    links:
      - db:db
    depends_on:
      - db

  db:
    image: postgres
    environment:
        POSTGRES_DB: "DBname"
        POSTGRES_HOST_AUTH_METHOD: "trust"
    ports:
        - 5432:5432

  client:
    build:
      context: ./appfrontend
      dockerfile: Dockerfile
    image: clientimgtest1
    container_name: clientcontest1
    depends_on:
      - server
    ports:
      - 3000:3000

However, I still see the error which says the relation does not exist. Is there any way I could achieve migrations through commands in dockerFile?

Source: Docker Questions

LEAVE A COMMENT