When the alembic console-script entry point runs, Python sets sys.path[0] to the entry point directory (/usr/local/bin/), not the WORKDIR. Without PYTHONPATH=/app, `from app.models import Base` in alembic/env.py fails with ModuleNotFoundError. uvicorn is unaffected as it adds CWD to sys.path itself. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
16 lines
358 B
Docker
16 lines
358 B
Docker
FROM python:3.12-slim
|
|
|
|
WORKDIR /app
|
|
ENV PYTHONPATH=/app
|
|
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
gcc libpq-dev \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
COPY requirements.txt .
|
|
RUN pip install --no-cache-dir -r requirements.txt
|
|
|
|
COPY . .
|
|
|
|
CMD ["sh", "-c", "alembic upgrade head && uvicorn app.main:app --host 0.0.0.0 --port 8000"]
|