I create a django docker application image. in my django app, in settings.py DATABASE entry is:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'cath_local',
'USER': 'postgres',
'PASSWORD': 'mypass',
'HOST': 'postgres',
'PORT': '5432',
'OPTIONS': {
'client_encoding': 'UTF8',
},
}
}
well, at this point i create my docker image using docker build command; all done.
Before running my django app docker image i run:
docker run -it postgres
image is downloaded and container start correctly
but when i run my django app
docker run -it cath2019/cathedral_studio:latest
but wher python manage.py runserver command into my Dockerfile start i get this error:
conn = _connect(dsn, connection_factory=connection_factory, **kwasync) django.db.utils.OperationalError: could not translate host name "postgres" to address: Name does not resolve
here my app Dockerfile:
FROM python:3.6-alpine
RUN apk add --no-cache make linux-headers libffi-dev jpeg-dev zlib-dev
RUN apk update && apk add postgresql-dev gcc python3-dev musl-dev
#RUN apk update && apk add build-essential libssl-dev libffi-dev
RUN mkdir /Code
WORKDIR /Code
COPY ./requirements.txt .
RUN pip install --upgrade pip
RUN pip install -r requirements.txt
ENV PYTHONUNBUFFERED 1
COPY . /Code/
ENTRYPOINT python /Code/core/manage.py runserver 0.0.0.0:8000
How can i connect into my django settings DATABASE to running postgres container?
So many thanks in advance

10.0.2.2but you'll have to map the port when running postgres too, I'd recommend keeping it as it is and just using a docker-compose file