I'm using docker-compose on Ubuntu 20.04. I have this docker-compose.yml file -- two services, a PostGres DB and a Python/Django app
version: "3.3"
services:
pgdb:
image: postgres
container_name: postgres-Django
ports:
- 5433:5432
environment:
- POSTGRES_DB=postgres
- POSTGRES_USER=userName
- POSTGRES_PASSWORD=Password
django:
build: .
container_name: django
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/vol/app
ports:
- "8000:8000"
environment:
DEBUG: 'true'
depends_on:
- pgdb
This is the Dockerfile used to build the Python/Django container
FROM python:3.8-alpine
ADD . /app
WORKDIR /app
COPY ./requirements.txt /app/requirements.txt
RUN python -m pip install -r requirements.txt
COPY . /app
Requirements.txt file content
Django==2.2
gunicorn==20.0.4
psycopg2-binary==2.8.6
psycopg2==2.8.6
Python setting.py file DB related content:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'postgres',
'USER': 'postgres',
'PASSWORD': 'admin',
'HOST': 'pgdb',
'PORT': 5432
}
}
Note: HOSTNAME pgdb is the same written in docker-compose postgres service
When I execute command "docker-compose run django(django app service name) python manage.py migrate", It throws exception "psycopg2 module not found" even its available in txt file and same django app configurations working fine when execute locally.
I also tried by installing dependent libraries "libpq-dev and python3-psycopg2" but no luck
Any help please how to get rid of this problem?