1

These are my docker files getting this error while changing my engine from SQLite to PostgreSQL. Doing it for the first time following book called Django for professionals docker-compose.yml

services:
  web:
    build: .
    command: python /code/manage.py runserver 0.0.0.0:8000
    volumes:
    - .:/code
    ports:
    - 8000:8000
    depends_on:
    - db
  db:
    image: postgres
    volumes:
      - postgres_data:/var/lib/postgresql/data/

volumes:
  postgres_data:

dockerfile

FROM python:3.9.6

#set environment variables

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

#set work directory
WORKDIR /code

#install dependencies
COPY Pipfile Pipfile.lock /code/
RUN pip install pipenv && pipenv install --system

# Copy project
COPY . /code/
6
  • hi, have you tried adding ports to db as you did on web? for example, ports: - 5432:5432 Commented Jul 18, 2022 at 4:02
  • yes i have port 5432 in my settings.py file Commented Jul 18, 2022 at 5:47
  • oh, i meant ports parameter in docker-compose.yml. from what you posted, your db does not have ports. Commented Jul 18, 2022 at 5:50
  • no I'm not using any port parameters in db. but that worked for me. Commented Jul 18, 2022 at 5:54
  • What command are you running that produces that error? What's the CMD the Docker image should normally run? Commented Jul 18, 2022 at 11:10

2 Answers 2

1

as suggested by seoul kim above i added ports: -5432:5432 and it worked for me.

Sign up to request clarification or add additional context in comments.

Comments

0

hello i think that your problem is in the setting.py and in dtabases change the db to local host or 127.0.0.1

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.