Docker compose run migrations on django web application + postgres db

Hi I am having issues running migrations on postgres db container from django.

Here is my docker-compose file

  • Phoenix production config reloading problems
  • How to setup default environment quickly in Docker?
  • Can't make outbound connections from haproxy-exporter docker
  • How to access mysql that which is in docker container from another host machine?
  • Is is possible to deploy a Docker image straight to AWS?
  • Force Docker to mount code volume in the host not the guest
  • web:
      restart: always
      build: ./web
      expose:
        - "8000"
      links:
        - postgres:postgres
      volumes:
        - /usr/src/app
        - /usr/src/app/static
      env_file:
        - ./.env
      environment:
        - DEBUG=1
      command: /usr/local/bin/gunicorn mysite.wsgi:application -w 2 -b :8000
    
    nginx:
      restart: always
      build: ./nginx/
      ports:
        - "80:80"
      volumes:
        - /www/static
      volumes_from:
        - web
      links:
        - web:web
    
    postgres:
      restart: always
      build: ./postgres
      env_file: .env
      ports:
        - "5432:5432"
      volumes:
        - pgdata:/var/lib/postgresql/data/
    

    The directory structure is below. enter image description here

    The .env file defines the Postgres DB , user name and password

    DB_NAME=test
    DB_USER=test
    DB_PASS=test!
    DB_SERVICE=postgres
    DB_PORT=5432
    POSTGRES_USER=test
    POSTGRES_DB=test
    POSTGRES_PASSWORD=test!
    

    When I run docker-compose build and docker-compose up -d nginx, postgres and web containers start. The postgres startup (default) creates the db, user and password. The django startup container installs requirements.txt and starts the django server (everything looks good).

    On running makemigrations

    docker-compose run web /usr/local/bin/python manage.py makemigrations polls
    I get the following output

    Migrations for 'polls':
    0001_initial.py:
    - Create model Choice
    - Create model Question
    - Add field question to choice

    But when I run

    docker-compose run web /usr/local/bin/python manage.py showmigrations polls
    the output is.

    polls
    (no migrations)

    on running
    docker-compose run web /usr/local/bin/python manage.py migrate --fake polls
    the output I see

    Operations to perform:
    Apply all migrations: (none)
    Running migrations:
    No migrations to apply.
    Your models have changes that are not yet reflected in a migration, and so won't be applied.
    Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them.

    The tables are not created in postgres. What am I doing wrong ? Sorry for the long post but I wanted to put all the details here.

  • build Docker images from GitLab
  • Migrating from shared development database to single database for each developer
  • Docker for Mac tutorial- overlapping export paths
  • Docker Container/AWS EC2 Public DNS Refusing to Connect
  • no fontmanager in java.library.path
  • Is it possible/sane to develop within a container Docker
  • Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.