FROM python:3.14-slim
ENV PYTHONUNBUFFERED=1
WORKDIR /code
# Install system dependencies for building Python packages
RUN apt-get update && \
apt-get install -y --no-install-recommends build-essential && \
rm -rf /var/lib/apt/lists/*
# Copy dependency definition first to leverage Docker cache
COPY pyproject.toml /code/pyproject.toml
COPY uv.lock /code/uv.lock 2>/dev/null || true
# Install Python dependencies (build backend in pyproject will handle installation)
RUN pip install --upgrade pip setuptools wheel
RUN if [ -f pyproject.toml ]; then \
pip install --no-cache-dir .; \
else \
echo "No pyproject.toml found; attempting to install from source is not possible"; \
fi
# Copy the rest of the source code
COPY . /code/
# Default command to verify the container runs
CMD ["python", "-c", "import fastapi,sys; print('fastapi version', fastapi.__version__); print('Python', sys.version)"]
Concerns: FROM python:3.14-slim likely does not exist; the tag may be invalid or unavailable in the public registry., COPY . /code/ occurs after a RUN that installs dependencies from /code, so the package installation may run against an incomplete context (no actual source files copied yet). This may cause the build to fail or install an empty package., The build copies uv.lock, which is not a standard Python lock file; dependency resolution may be unclear or unused., The final CMD only prints versions and does not start a web service, so the container may not actually serve requests. If the goal is a web service, consider starting the app (e.g., via uvicorn) and exposing a port., Overall the sequence and intent around packaging (pyproject.toml usage with pip install .) is fragile and may not work as written without the source being present at build time.
Summary (under 1500 chars):
- Build system: requires = ["pdm-backend"]; build-backend = "pdm.backend"
- Project: name = "fastapi"; dynamic = ["version"]; requires-python = ">=3.10"; license = "MIT"; license-files = ["LICENSE"]; authors = Sebastián Ramírez; readme, URLs, classifiers listed
- Core dependencies: starlette>=0.46.0; pydantic>=2.9.0; typing-extensions>=4.8.0; typing-inspection>=0.4.2; annotated-doc>=0.0.2
- Project URLs: Homepage = https://github.com/fastapi/fastapi; Documentation = https://fastapi.tiangolo.com/; Repository = https://github.com/fastapi/fastapi; Issues = https://github.com/fastapi/fastapi/issues; Changelog = https://fastapi.tiangolo.com/release-notes/
- Optional dependencies (groups):
- standard: fastapi-cli[standard] >=0.0.8; httpx >=0.23.0,<1.0.0; jinja2 >=3.1.5; python-multipart >=0.0.18; email-validator >=2.0.0; uvicorn[standard] >=0.12.0; pydantic-settings >=2.0.0; pydantic-extra-types >=2.0.0
- standard-no-fastapi-cloud-cli: fastapi-cli[standard-no-fastapi-cloud-cli] >=0.0.8; httpx >=0.23.0,<1.0.0; jinja2 >=3.1.5; python-multipart >=0.0.18; email-validator >=2.0.0; uvicorn[standard] >=0.12.0; pydantic-settings >=2.0.0; pydantic-extra-types >=2.0.0
- all: fastapi-cli[standard] >=0.0.8; httpx >=0.23.0,<1.0.0; jinja2 >=3.1.5; python-multipart >=0.0.18; itsdangerous >=1.1.0; pyyaml >=5.3.1; email-validator >=2.0.0; uvicorn[standard] >=0.12.0; pydantic-settings >=2.0.0; pydantic-extra-types >=2.0.0
- Project scripts: fastapi = "fastapi.cli:main"
- Dependency groups: dev (tests, docs, translations; plus playwright >=1.57.0, prek >=0.2.22), docs (docs-tests; black >=25.1.0; cairosvg >=2.8.2; MkDocs plugins; etc.), docs-tests (httpx>=0.23.0,<1.0.0; ruff >=0.14.14; ujson >=5.8.0; orjson >=3.9.3), github-actions (httpx >=0.27.0,<1.0.0; pydantic >=2.9.0,<3.0.0; pydantic-settings >=2.1.0,<3.0.0; pygithub >=2.3.0,<3.0.0; pyyaml >=5.3.1,<7.0.0; smokeshow >=0.5.0), tests (docs-tests plus various test libs), translations (gitpython >=3.1.46; pydantic-ai >=0.4.10; pygithub >=2.8.1)
- PDM config: version = { source = "file", path = "fastapi/__init__.py" }; distribution = true
- Build include: source-includes = ["tests/", "docs_src/", "scripts/", "docs/en/docs/img/favicon.png"]
- MyPy: plugins = ["pydantic.mypy"]; strict = true; overrides for modules fastapi.concurrency, fastapi.tests.*, docs_src.* with various settings
- Pytest: minversion = "9.0"; addopts = ["--strict-config","--strict-markers","--ignore=docs_src"]; strict_xfail = true; filterwarnings = ["error"]; timeout = "20"
- Coverage: run parallel; data_file = "coverage/.coverage"; sources = ["docs_src","tests","fastapi"]; omit several docs/test examples; report sort = "-Cover"; html contexts on
- Ruff: lint select = ["E","W","F","I","B","C4","UP"]; ignore = ["E501","B008","C901","W191"]; per-file-ignores list for numerous files
- Ruff isort: known-third-party = ["fastapi","pydantic","starlette"]
- Ruff pyupgrade: keep-runtime-typing = true
- Inline-snapshot: default-flags commented outFROM python:3.14-slim
ENV PYTHONUNBUFFERED=1
WORKDIR /code
# Install essential build tools
RUN apt-get update && \
apt-get install -y --no-install-recommends build-essential ca-certificates curl git && \
rm -rf /var/lib/apt/lists/*
# Copy the entire repository
COPY . /code/
# Upgrade packaging tools
RUN python -m pip install --no-cache-dir --upgrade pip setuptools wheel
# Build the package from source and install it
RUN python -m pip install --no-cache-dir build && \
python -m build
# Install the built distribution
RUN ls -la dist/ || true
RUN if compgen -G 'dist/*.whl' > /dev/null; then \
python -m pip install --no-cache-dir dist/*.whl; \
else \
echo 'No wheel built yet'; \
fi
# Expose port for potential servers
EXPOSE 80
# Run a simple check to verify the container has the package available
CMD ["python","-c","import fastapi,sys; print('fastapi version:', fastapi.__version__); print('Python', sys.version)" ]
Concerns: FROM image tag 'python:3.14-slim' may not exist in the Docker Hub registry., RUN step uses 'compgen' in /bin/sh, but compgen is a Bash feature; this may fail in /bin/sh during build., Wheel installation depends on presence of a .whl in dist/; if the build only creates sdist, the wheel won't be installed and runtime may fail.
No results found.
FROM python:3.13-slim
ENV PYTHONUNBUFFERED=1
WORKDIR /code
# Install essential build tools and dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends build-essential ca-certificates curl git && \
rm -rf /var/lib/apt/lists/*
# Copy the repository into the image
COPY . /code/
# Install Python build tooling and dependencies, then install the package in editable mode
RUN python -m pip install --no-cache-dir --upgrade pip setuptools wheel
RUN python -m pip install --no-cache-dir -e ".[standard]"
# Expose a port (not strictly required for a library, but useful if someone wants to run a server in the image)
EXPOSE 80
# Basic check to ensure the local package is importable
CMD ["python", "-c", "import fastapi, sys; print('fastapi version:', fastapi.__version__); print('Python', sys.version)"]
Smoke [FAIL]: python -c \"import sys; print('Python version:', sys.version)\
Output: sh: 1: Syntax error: word unexpected (expecting ")")
Smoke [PASS]: python -m pip --versionFROM python:3.13-slim
ENV PYTHONUNBUFFERED=1
WORKDIR /code
# Install essential system dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends build-essential ca-certificates curl git && \
rm -rf /var/lib/apt/lists/*
# Copy the repository into the image
COPY . /code/
# Install Python build tooling and dependencies, then install the package in editable mode
RUN python -m pip install --no-cache-dir --upgrade pip setuptools wheel
RUN python -m pip install --no-cache-dir -e ".[standard]"
# Expose a port (not strictly required for a library, but useful if someone wants to run a server in the image)
EXPOSE 80
# Basic check to ensure the local package is importable
CMD ["python", "-c", "import fastapi, sys; print('fastapi version:', fastapi.__version__); print('Python', sys.version)"]
Concerns: Base image tag python:3.13-slim may not exist or be available in all registries; could fail if tag is not published., Installation uses -e '.[standard]' which requires a setup.cfg/pyproject with an extras_require['standard']; if the project doesn't define this extra, the install will fail., CMD only performs an import test and prints versions; it does not start the web service, so the container won't serve traffic out of the box.
Smoke [FAIL]: python -c "import fastapi, sys; print('fastapi version:', fastapi.__version__); print('Python', sys.version)
Output: sh: 1: Syntax error: Unterminated quoted string
Smoke [PASS]: python -m pip show fastapiFROM python:3.13-slim
ENV PYTHONUNBUFFERED=1
WORKDIR /code
# Install essential system dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends build-essential ca-certificates curl git && \
rm -rf /var/lib/apt/lists/*
# Copy the repository into the image
COPY . /code/
# Install Python build tooling and dependencies, then build the package from source
RUN python -m pip install --no-cache-dir --upgrade pip setuptools wheel
RUN python -m pip install --no-cache-dir build
RUN python -m build
# Install the built distribution and uvicorn for serving
RUN python -m pip install --no-cache-dir dist/*.whl
RUN python -m pip install --no-cache-dir uvicorn[standard]
# Create a minimal FastAPI app to run inside the container
RUN mkdir -p /code/app
RUN bash -lc 'cat > /code/app/main.py <<"PY"\nfrom fastapi import FastAPI\n\napp = FastAPI()\n\n\n@app.get("/")\ndef read_root():\n return {"hello": "world"}\nPY'
# Expose port for running the server
EXPOSE 80
# Start Uvicorn to serve the API
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"]
Concerns: The container runs a minimal FastAPI app that imports FastAPI, but the Dockerfile never explicitly installs the fastapi package. It only installs uvicorn[standard]. If the built distribution (dist/*.whl) does not bring FastAPI as a dependency, the runtime will fail with ModuleNotFoundError: FastAPI., Reliance on the build step (python -m build) requires a valid packaging configuration (pyproject.toml or setup.cfg). If the repository lacks proper packaging, the build will fail. The Dockerfile does not guard against this scenario., The app served by uvicorn (app.main:app) lives under /code/app/main.py, which is unrelated to the built package. This could cause confusion or conflicts if the project package and the in-repo app diverge in behavior.
FROM python:3.13-slim as builder
ENV PYTHONUNBUFFERED=1
WORKDIR /code
# Install essential build tools
RUN apt-get update && \
apt-get install -y --no-install-recommends build-essential curl ca-certificates git && \
rm -rf /var/lib/apt/lists/*
# Copy packaging metadata first for cache
COPY pyproject.toml /code/pyproject.toml
# Install build tooling
RUN python -m pip install --no-cache-dir --upgrade pip setuptools wheel
RUN python -m pip install --no-cache-dir build
# Copy the rest of the source
COPY . /code/
# Build the project (wheel + sdist)
RUN python -m build
FROM python:3.13-slim
ENV PYTHONUNBUFFERED=1
WORKDIR /code
# Install runtime deps
RUN apt-get update && \
apt-get install -y --no-install-recommends ca-certificates curl && \
rm -rf /var/lib/apt/lists/*
# Copy built artifacts from builder
COPY --from=builder /code/dist/*.whl /code/dist/ 2>/dev/null || true
# Install the built distribution if available
RUN python -m pip install --no-cache-dir /code/dist/*.whl 2>/dev/null || true
# Ensure uvicorn is available for serving examples
RUN python -m pip install --no-cache-dir uvicorn[standard] fastapi
# Create a minimal app to run inside the container
RUN mkdir -p /code/app
RUN bash -lc 'cat > /code/app/main.py <<"PY"\nfrom fastapi import FastAPI\n\napp = FastAPI()\n\n@app.get("/")\ndef read_root():\n return {"hello": "world"}\nPY'
EXPOSE 80
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"]
Concerns: COPY --from=builder /code/dist/*.whl /code/dist/ 2>/dev/null || true contains shell redirection inside a COPY instruction, which is invalid Dockerfile syntax. Docker COPY does not interpret shell operators like redirection or || true., Even if the intent is to swallow errors, the redirection belongs in a RUN instruction, not in COPY. This will cause a build failure., Potential issue: if no wheel is produced, the final image may not have the wheel installed due to the faulty COPY syntax; this could lead to runtime issues.
FROM python:3.13-slim as builder
ENV PYTHONUNBUFFERED=1
WORKDIR /code
# Install essential build tools
RUN apt-get update && \
apt-get install -y --no-install-recommends build-essential curl ca-certificates git && \
rm -rf /var/lib/apt/lists/*
# Copy packaging metadata first for cache
COPY pyproject.toml /code/pyproject.toml
# Install build tooling
RUN python -m pip install --no-cache-dir --upgrade pip setuptools wheel
RUN python -m pip install --no-cache-dir build
# Copy the rest of the source
COPY . /code/
# Build the project (wheel + sdist)
RUN python -m build
FROM python:3.13-slim
ENV PYTHONUNBUFFERED=1
WORKDIR /code
# Install runtime deps
RUN apt-get update && \
apt-get install -y --no-install-recommends ca-certificates curl && \
rm -rf /var/lib/apt/lists/*
# Copy built artifacts from builder if present
COPY --from=builder /code/dist/*.whl /code/dist/ 2>/dev/null || true
# Install the built distribution if available
RUN python -m pip install --no-cache-dir /code/dist/*.whl 2>/dev/null || true
# Ensure uvicorn is available for serving examples
RUN python -m pip install --no-cache-dir uvicorn[standard] fastapi
# Create a minimal app to run inside the container
RUN mkdir -p /code/app
RUN bash -lc 'cat > /code/app/main.py <<"PY"\nfrom fastapi import FastAPI\n\napp = FastAPI()\n\n@app.get("/")\ndef read_root():\n return {"hello": "world"}\nPY'
EXPOSE 80
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"]
Concerns: FROM python:3.13-slim may not be available in the official registry (3.13 tag may not exist yet)., COPY --from=builder /code/dist/*.whl /code/dist/ 2>/dev/null || true is invalid syntax for a COPY instruction; redirection and shell operators are not allowed in COPY., The second-stage RUN uses '2>/dev/null || true' which swallows installation failures and could leave dependencies unmet without visible errors.
FROM python:3.13-slim AS builder
ENV PYTHONUNBUFFERED=1
WORKDIR /code
# Install essential build tools
RUN apt-get update && \
apt-get install -y --no-install-recommends build-essential curl ca-certificates git && \
rm -rf /var/lib/apt/lists/*
# Copy packaging metadata first for cache
COPY pyproject.toml /code/pyproject.toml
# Install build tooling
RUN python -m pip install --no-cache-dir --upgrade pip setuptools wheel
RUN python -m pip install --no-cache-dir build
# Copy the rest of the source
COPY . /code/
# Build the project (wheel + sdist)
RUN python -m build
FROM python:3.13-slim
ENV PYTHONUNBUFFERED=1
WORKDIR /code
# Install runtime deps
RUN apt-get update && \
apt-get install -y --no-install-recommends ca-certificates curl && \
rm -rf /var/lib/apt/lists/*
# Copy built artifacts from builder if present
COPY --from=builder /code/dist /code/dist
# Install the built distribution
RUN python -m pip install --no-cache-dir /code/dist/*.whl
# Ensure uvicorn is available for serving
RUN python -m pip install --no-cache-dir uvicorn[standard] fastapi
# Create a minimal app to run inside the container
RUN mkdir -p /code/app
RUN bash -lc 'cat > /code/app/main.py <<"PY"\nfrom fastapi import FastAPI\n\napp = FastAPI()\n\n@app.get("/")\ndef read_root():\n return {"hello": "world"}\nPY'
EXPOSE 80
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"]
Summary (concise)
- Exact error messages and exit code
- bash: line 1: warning: here-document at line 1 delimited by end-of-file (wanted `PYnfrom')
- bash: -c: line 1: syntax error near unexpected token `('
- bash: -c: line 1: `cat > /code/app/main.py <<"PY"\nfrom fastapi import FastAPI\n\napp = FastAPI()\n\n@app.get(\"/\")\ndef read_root():\n return {\"hello\": \"world\"}\nPY'
- ERROR: failed to build: failed to solve: process "/bin/sh -c bash -lc 'cat > /code/app/main.py <<\"PY\"\\nfrom fastapi import FastAPI\\n\\napp = FastAPI()\\n\\n@app.get(\"/\")\\ndef read_root():\\n return {\"hello\": \"world\"}\\nPY'" did not complete successfully: exit code: 2
- Failing command/step
- Stage-1, step 8/8: RUN bash -lc 'cat > /code/app/main.py <<"PY"\nfrom fastapi import FastAPI\n\napp = FastAPI()\n\n@app.get("/")\ndef read_root():\n return {"hello": "world"}\nPY'
- Missing packages/files mentioned
- None. The log does not indicate missing packages or files; the failure is due to a here-document/shell syntax issue in the command that writes /code/app/main.py.
- Version mismatch info
- Base image: python:3.13-slim (Debian trixie). No explicit version mismatch is reported; the error arises from the here-document syntax in the command, not from a version conflict.FROM python:3.13-slim AS builder
ENV PYTHONUNBUFFERED=1
WORKDIR /code
# Install essential build tools
RUN apt-get update && \
apt-get install -y --no-install-recommends build-essential curl ca-certificates git && \
rm -rf /var/lib/apt/lists/*
# Copy packaging metadata first for cache
COPY pyproject.toml /code/pyproject.toml
# Install build tooling
RUN python -m pip install --no-cache-dir --upgrade pip setuptools wheel
RUN python -m pip install --no-cache-dir build
# Copy the rest of the source
COPY . /code/
# Build the project (wheel + sdist)
RUN python -m build
FROM python:3.13-slim
ENV PYTHONUNBUFFERED=1
WORKDIR /code
# Install runtime deps
RUN apt-get update && \
apt-get install -y --no-install-recommends ca-certificates curl && \
rm -rf /var/lib/apt/lists/*
# Copy built artifacts from builder if present
COPY --from=builder /code/dist /code/dist
# Install the built distribution
RUN python -m pip install --no-cache-dir /code/dist/*.whl
# Ensure uvicorn is available for serving
RUN python -m pip install --no-cache-dir uvicorn[standard] fastapi
# Create a minimal app to run inside the container
RUN mkdir -p /code/app
RUN printf '%s
' 'from fastapi import FastAPI' '' 'app = FastAPI()' '' '@app.get("/")' 'def read_root():' ' return {"hello": "world"}' > /code/app/main.py
EXPOSE 80
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"]
Concerns: The RUN command that creates /code/app/main.py uses printf with a newline in the format ('RUN printf '%s
' ...'), which will only print the first line ('from fastapi import FastAPI') and disregard the remaining lines. As a result, /code/app/main.py will be incomplete and uvicorn will fail to find app.main.app at runtime., Due to the above, the container will likely fail at startup even though the image builds, since the FastAPI app object isn't defined in app.main., Overall build steps look reasonable and the multi-stage approach is fine, but the critical Run instruction content for the app file is broken.FROM python:3.13-slim AS builder
ENV PYTHONUNBUFFERED=1
WORKDIR /code
# Install essential build tools
RUN apt-get update && \
apt-get install -y --no-install-recommends build-essential curl ca-certificates git && \
rm -rf /var/lib/apt/lists/*
# Copy packaging metadata first for cache
COPY pyproject.toml /code/pyproject.toml
# Install build tooling
RUN python -m pip install --no-cache-dir --upgrade pip setuptools wheel
RUN python -m pip install --no-cache-dir build
# Copy the rest of the source
COPY . /code/
# Build the project (wheel + sdist)
RUN python -m build
FROM python:3.13-slim
ENV PYTHONUNBUFFERED=1
WORKDIR /code
# Install runtime deps
RUN apt-get update && \
apt-get install -y --no-install-recommends ca-certificates curl && \
rm -rf /var/lib/apt/lists/*
# Copy built artifacts from builder if present
COPY --from=builder /code/dist /code/dist
# Install the built distribution
RUN python -m pip install --no-cache-dir /code/dist/*.whl
# Ensure uvicorn is available for serving
RUN python -m pip install --no-cache-dir uvicorn[standard] fastapi
# Create a minimal app to run inside the container
RUN mkdir -p /code/app
RUN printf "from fastapi import FastAPI\n\napp = FastAPI()\n\n@app.get(\"/\")\ndef read_root():\n return {\"hello\": \"world\"}\n" > /code/app/main.py
EXPOSE 80
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"]
Concerns: The final image runs a minimal FastAPI app at /code/app/main.py instead of using the built distribution from /code/dist; the wheel installed from the build is not used, so the deployment may not reflect the actual application built from source., Using Python 3.13-slim as the base image may be problematic if the tag does not exist in the registry; verify the tag is available in CI/production environments., Consider adding a HEALTHCHECK and aligning the runtime behavior with the built package (e.g., run the package's entry point or expose the actual app) to improve observability and correctness. Smoke [PASS]: test -f /code/app/main.py Smoke [PASS]: test -d /code/dist && ls -1 /code/dist | head -n 1 Smoke [FAIL]: python -c 'import uvicorn; print(uvicorn.__version__) Output: sh: 1: Syntax error: Unterminated quoted string
FROM python:3.13-slim AS builder
ENV PYTHONUNBUFFERED=1
WORKDIR /code
# Install essential build tools
RUN apt-get update && \
apt-get install -y --no-install-recommends build-essential curl ca-certificates git && \
rm -rf /var/lib/apt/lists/*
# Copy packaging metadata first for cache
COPY pyproject.toml /code/pyproject.toml
# Install build tooling
RUN python -m pip install --no-cache-dir --upgrade pip setuptools wheel
RUN python -m pip install --no-cache-dir build
# Copy the rest of the source
COPY . /code/
# Build the project (wheel + sdist)
RUN python -m build
FROM python:3.13-slim
ENV PYTHONUNBUFFERED=1
WORKDIR /code
# Install runtime deps
RUN apt-get update && \
apt-get install -y --no-install-recommends ca-certificates curl && \
rm -rf /var/lib/apt/lists/*
# Copy built artifacts from builder if present
COPY --from=builder /code/dist /code/dist
# Install the built distribution
RUN python -m pip install --no-cache-dir /code/dist/*.whl
# Ensure uvicorn is available for serving
RUN python -m pip install --no-cache-dir uvicorn[standard] fastapi
# Create a minimal app to run inside the container
RUN mkdir -p /code/app
RUN bash -lc 'cat > /code/app/main.py <<"PY"\nfrom fastapi import FastAPI\n\napp = FastAPI()\n\n@app.get("/")\ndef read_root():\n return {"hello": "world"}\nPY'
EXPOSE 80
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"]
Summary of Docker build error
- Exact error message and exit code
- ERROR: process "/bin/sh -c bash -lc 'cat > /code/app/main.py <<"PY"\\nfrom fastapi import FastAPI\\n\\napp = FastAPI()\\n\\n@app.get(\"/\")\\ndef read_root():\\n return {\"hello\": \"world\"}\\nPY'" did not complete successfully: exit code: 2
- Additional shell output shown:
- bash: line 1: warning: here-document at line 1 delimited by end-of-file (wanted `PYnfrom')
- bash: -c: line 1: syntax error near unexpected token `('
- bash: -c: line 1: `cat > /code/app/main.py <<"PY"\\nfrom fastapi import FastAPI\\n\\napp = FastAPI()\\n\\n@app.get(\"/\")\\ndef read_root():\\n return {\"hello\": \"world\"}\\nPY'
- Failing command/step
- [stage-1 8/8] RUN bash -lc 'cat > /code/app/main.py <<"PY"\nfrom fastapi import FastAPI\n\napp = FastAPI()\n\n@app.get("/")\ndef read_root():\n return {"hello": "world"}\nPY'
- Missing packages or files mentioned
- None mentioned as missing. The failure is due to a shell here-document syntax error in the RUN command, not a missing package/file.
- Version mismatch info
- No version mismatch information present in the log. Base image used earlier is python:3.13-slim, but no mismatch is reported.FROM python:3.13-slim AS builder
ENV PYTHONUNBUFFERED=1
WORKDIR /code
# Install essential build tools
RUN apt-get update && \
apt-get install -y --no-install-recommends build-essential curl ca-certificates git && \
rm -rf /var/lib/apt/lists/*
# Copy packaging metadata first for cache
COPY pyproject.toml /code/pyproject.toml
# Install build tooling
RUN python -m pip install --no-cache-dir --upgrade pip setuptools wheel
RUN python -m pip install --no-cache-dir build
# Copy the rest of the source
COPY . /code/
# Build the project (wheel + sdist)
RUN python -m build
FROM python:3.13-slim
ENV PYTHONUNBUFFERED=1
WORKDIR /code
# Install runtime deps
RUN apt-get update && \
apt-get install -y --no-install-recommends ca-certificates curl && \
rm -rf /var/lib/apt/lists/*
# Copy built artifacts from builder if present
COPY --from=builder /code/dist /code/dist
# Install the built distribution
RUN python -m pip install --no-cache-dir /code/dist/*.whl
# Ensure uvicorn is available for serving
RUN python -m pip install --no-cache-dir uvicorn[standard] fastapi
# Create a minimal app to run inside the container
RUN mkdir -p /code/app
RUN bash -lc 'cat > /code/app/main.py <<"PY"\nfrom fastapi import FastAPI\n\napp = FastAPI()\n\n@app.get("/")\ndef read_root():\n return {"hello": "world"}\nPY'
EXPOSE 80
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"]
FROM python:3.12-slim as builder
ENV PYTHONUNBUFFERED=1
# Install build dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends build-essential && \
rm -rf /var/lib/apt/lists/*
WORKDIR /code
# Copy only the project manifest first to leverage build cache for dependencies
COPY pyproject.toml ./
# Ensure pip tooling is up to date and install the build toolchain
RUN python -m pip install --upgrade pip setuptools wheel
RUN python -m pip install build
# Copy the rest of the source code
COPY . .
# Build a wheel from the source
RUN python -m build --wheel --no-isolation
FROM python:3.12-slim
ENV PYTHONUNBUFFERED=1
WORKDIR /code
# Copy the built wheel from the builder stage
COPY --from=builder /code/dist/*.whl /tmp/
# Install the built package (and its runtime dependencies)
RUN python -m pip install --no-cache-dir /tmp/*.whl && \
rm -rf /tmp/*.whl
# Basic smoke test to ensure the package is importable
RUN python -c "import fastapi; print('fastapi', fastapi.__version__)"
# Default command: just print the version to verify container runs
CMD ["python", "-c", "import fastapi; print(fastapi.__version__)" ]
- Failing step: [builder 8/8] RUN python -m build --wheel --no-isolation
- Exact error message and exit code:
ERROR Backend 'pdm.backend' is not available.
Traceback (most recent call last):
File "/usr/local/lib/python3.12/site-packages/pyproject_hooks/_impl.py", line 402, in _call_hook
raise BackendUnavailable(
pyproject_hooks._impl.BackendUnavailable: Cannot import 'pdm.backend'
ERROR: process "/bin/sh -c python -m build --wheel --no-isolation" did not complete successfully: exit code: 1
- Missing packages/files mentioned:
- Cannot import 'pdm.backend' (missing pdm backend)
- Version mismatch info:
- No explicit version mismatch reported. Base image uses python:3.12-slim.FROM python:3.12-slim as builder
ENV PYTHONUNBUFFERED=1
# Install build dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends build-essential && \
rm -rf /var/lib/apt/lists/*
WORKDIR /code
# Copy only the project manifest first to leverage build cache for dependencies
COPY pyproject.toml ./
# Ensure pip tooling is up to date and install the build toolchain
RUN python -m pip install --upgrade pip setuptools wheel
# Install pdm to provide the build backend referenced by pyproject.toml
RUN python -m pip install pdm
# Copy the rest of the source code
COPY . .
# Build a wheel from the source
RUN python -m build --wheel --no-isolation
FROM python:3.12-slim
ENV PYTHONUNBUFFERED=1
WORKDIR /code
# Copy the built wheel from the builder stage
COPY --from=builder /code/dist/*.whl /tmp/
# Install the built package (and its runtime dependencies)
RUN python -m pip install --no-cache-dir /tmp/*.whl && \
rm -rf /tmp/*.whl
# Basic smoke test to ensure the package is importable
RUN python -c "import fastapi; print('fastapi', fastapi.__version__)"
# Default command: print the version to verify container runs
CMD ["python", "-c", "import fastapi; print(fastapi.__version__)" ]
FROM python:3.12-slim as builder
ENV PYTHONUNBUFFERED=1
# Install build dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends build-essential && \
rm -rf /var/lib/apt/lists/*
WORKDIR /code
# Copy only the project manifest first to leverage build cache for dependencies
COPY pyproject.toml ./
# Ensure pip tooling is up to date and install the build toolchain
RUN python -m pip install --upgrade pip setuptools wheel
# Install pdm to provide the build backend referenced by pyproject.toml
RUN python -m pip install pdm
# Also install the pdm backend explicitly to satisfy the build backend import
RUN python -m pip install pdm-backend
# Copy the rest of the source code
COPY . .
# Build a wheel from the source
RUN python -m build --wheel --no-isolation
FROM python:3.12-slim
ENV PYTHONUNBUFFERED=1
WORKDIR /code
# Copy the built wheel from the builder stage
COPY --from=builder /code/dist/*.whl /tmp/
# Install the built package (and its runtime dependencies)
RUN python -m pip install --no-cache-dir /tmp/*.whl && \
rm -rf /tmp/*.whl
# Basic smoke test to ensure the package is importable
RUN python -c "import fastapi; print('fastapi', fastapi.__version__)"
# Default command: print the version to verify container runs
CMD ["python", "-c", "import fastapi; print(fastapi.__version__)" ]
- Exact error message and exit code - /usr/local/bin/python: No module named build - exit code: 1 - Failing command/step - [builder 9/9] RUN python -m build --wheel --no-isolation - Missing packages or files mentioned - The Python module "build" is missing (No module named build). This typically requires installing the build package (pip install build) or ensuring the build tooling is present in the image. - Version mismatch info (and related warnings) - Warning: FromAsCasing: 'as' and 'FROM' keywords' casing do not match (line 1) - No other explicit version mismatch information shown
FROM python:3.12-slim as builder
ENV PYTHONUNBUFFERED=1
# Install build dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends build-essential curl ca-certificates && \
rm -rf /var/lib/apt/lists/*
WORKDIR /code
# Copy pyproject.toml first to leverage Docker cache for dependencies
COPY pyproject.toml ./
# Install Python build tooling
RUN python -m pip install --upgrade pip setuptools wheel
RUN python -m pip install build pdm
# Copy the rest of the source code
COPY . .
# Build a wheel from the source
RUN python -m build --wheel --no-isolation
FROM python:3.12-slim
ENV PYTHONUNBUFFERED=1
WORKDIR /code
# Copy the built wheel from the builder stage
COPY --from=builder /code/dist/*.whl /tmp/
# Install the built package (and its runtime dependencies)
RUN python -m pip install --no-cache-dir /tmp/*.whl && \
rm -rf /tmp/*.whl
# Basic smoke test to ensure the package is importable
RUN python -c "import fastapi; print('fastapi', fastapi.__version__)"
# Default command: verify import at runtime
CMD ["python", "-c", "import fastapi; print(fastapi.__version__)"]