0

Hello I can not dockerize my django app because I got an error -

listen tcp4 0.0.0.0:5433: bind: address already in use

From the other hand, when I "kill" 5433 port in ubuntu terminal I get this error

Is the server running on host "localhost" (::1) and accepting
web_1  |        TCP/IP connections on port 5433?

What can I do to solve this problem and dockerize successfully my app? Dockerfile

FROM python:3

RUN adduser --system --no-create-home django

ENV PYTHONUNBUFFERED=1
WORKDIR /code
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
ENV PYTHONPATH /code



EXPOSE 8000
USER django

CMD ["./main.py"]

docker-compose

version: "3"
   
services:
  

    db:
        image: postgres
        volumes:
          - ./data/db:/var/lib/postgresql/data
        environment:
          - POSTGRES_DB=fitshop
          - POSTGRES_USER=fituser
          - POSTGRES_PASSWORD=fitpass
        ports:
          - "5433:5433"
      web:
        build: .
        command: python manage.py runserver 0.0.0.0:8000
        volumes:
          - .:/code
        restart: always
        ports:
          - "8000:8000"
        depends_on:
          - db

settings.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'fitshop',
        'USER': 'fituser',
        'PASSWORD': 'fitpass',
        'HOST': 'localhost',
        'PORT': '5433',
    }
}

2 Answers 2

1

You should use "db" as host here. In a docker-compose setup each service is started in a separate Container and the /etc/hosts config of all containers is modified so, that each container can find the other containers via the service names.

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

1 Comment

'PASSWORD': 'fitpass', 'HOST': 'db', 'PORT': '5433', i Get same error, port in use
0

I`ve got it!. In 'localhost" port of postgres was 5433 but for 'db' as HOST it was default, 5432.

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.