docker / docs

Source repo for Docker's Documentation
https://docs.docker.com
Apache License 2.0
4.17k stars 7.29k forks source link

Cannot assign requested address #20434

Closed rrafay closed 3 months ago

rrafay commented 3 months ago

Is this a docs issue?

Type of issue

Other

Description

The documentation for Python states that docker compose up --build should yield a successful response, however I am getting the error: Cannot assign requested address. Postgres container runs successfully but the other container shuts down after staring.

The log of the error is:

python-docker-dev-db-1      | PostgreSQL Database directory appears to contain a database; Skipping initialization
python-docker-dev-db-1      | 
python-docker-dev-db-1      | 2024-07-17 21:15:23.481 UTC [1] LOG:  starting PostgreSQL 16.3 (Debian 16.3-1.pgdg120+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
python-docker-dev-db-1      | 2024-07-17 21:15:23.481 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
python-docker-dev-db-1      | 2024-07-17 21:15:23.482 UTC [1] LOG:  listening on IPv6 address "::", port 5432
python-docker-dev-db-1      | 2024-07-17 21:15:23.485 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
python-docker-dev-db-1      | 2024-07-17 21:15:23.490 UTC [17] LOG:  database system was shut down at 2024-07-17 21:05:39 UTC
python-docker-dev-db-1      | 2024-07-17 21:15:23.499 UTC [1] LOG:  database system is ready to accept connections
python-docker-dev-server-1  |  * Debug mode: off
python-docker-dev-server-1  | Cannot assign requested address
python-docker-dev-server-1 exited with code 1 

I have confirmed that both port 8001 and 5432 are not in use.

My yaml file and Dockerfile looks like this:

yaml


services:
  server:
    build:
      context: .
    ports:
      - 8001:8001
    environment:
      - POSTGRES_PASSWORD_FILE=/run/secrets/db-password
    depends_on:
      db:
        condition: service_healthy
    secrets:
      - db-password
  db:
    image: postgres
    restart: always
    user: postgres
    secrets:
      - db-password
    volumes:
      - db-data:/var/lib/postgresql/data
    environment:
      - POSTGRES_DB=example
      - POSTGRES_PASSWORD_FILE=/run/secrets/db-password
    expose:
      - 5432
    healthcheck:
      test: ["CMD", "pg_isready"]
      interval: 10s
      timeout: 5s
      retries: 5
volumes:
  db-data:
secrets:
  db-password:
    file: db/password.txt

Dockerfile

# syntax=docker/dockerfile:1

ARG PYTHON_VERSION=3.12.0
FROM python:${PYTHON_VERSION} as base

ENV PYTHONDONTWRITEBYTECODE=1

ENV PYTHONUNBUFFERED=1

WORKDIR /app

ARG UID=10001
RUN adduser \
    --disabled-password \
    --gecos "" \
    --home "/nonexistent" \
    --shell "/sbin/nologin" \
    --no-create-home \
    --uid "${UID}" \
    appuser

RUN --mount=type=cache,target=/root/.cache/pip \
    --mount=type=bind,source=requirements.txt,target=requirements.txt \
    python -m pip install -r requirements.txt

USER appuser

COPY . .

EXPOSE 8001

CMD python3 -m flask run --host=0.0.0.0 --host=8001

Thanks.

Location

https://docs.docker.com/language/python/develop/

Suggestion

No response

rrafay commented 3 months ago

Typo in Dockerfile. Change CMD python3 -m flask run --host=0.0.0.0 --host=8001 to CMD python3 -m flask run --host=0.0.0.0 --port=8001

docker-robot[bot] commented 2 months ago

Closed issues are locked after 30 days of inactivity. This helps our team focus on active issues.

If you have found a problem that seems similar to this, please open a new issue.

/lifecycle locked