@@ -14,20 +14,23 @@ ENV UV_COMPILE_BYTECODE=1
1414# Copy from the cache instead of linking since it's a mounted volume
1515ENV UV_LINK_MODE=copy
1616
17+ # Omit development dependencies
18+ ENV UV_NO_DEV=1
19+
1720# Ensure installed tools can be executed out of the box
1821ENV UV_TOOL_BIN_DIR=/usr/local/bin
1922
2023# Install the project's dependencies using the lockfile and settings
2124RUN --mount=type=cache,target=/root/.cache/uv \
2225 --mount=type=bind,source=uv.lock,target=uv.lock \
2326 --mount=type=bind,source=pyproject.toml,target=pyproject.toml \
24- uv sync --locked --no-install-project --no-dev
27+ uv sync --locked --no-install-project
2528
2629# Then, add the rest of the project source code and install it
2730# Installing separately from its dependencies allows optimal layer caching
2831COPY . /app
2932RUN --mount=type=cache,target=/root/.cache/uv \
30- uv sync --locked --no-dev
33+ uv sync --locked
3134
3235# Place executables in the environment at the front of the path
3336ENV PATH="/app/.venv/bin:$PATH"
@@ -39,7 +42,8 @@ ENTRYPOINT []
3942USER nonroot
4043
4144# Run the FastAPI application by default
45+ # Uses `uv run` to sync dependencies on startup, respecting UV_NO_DEV
4246# Uses `fastapi dev` to enable hot-reloading when the `watch` sync occurs
4347# Uses `--host 0.0.0.0` to allow access from outside the container
4448# Note in production, you should use `fastapi run` instead
45- CMD ["fastapi" , "dev" , "--host" , "0.0.0.0" , "src/uv_docker_example" ]
49+ CMD ["uv" , "run" , " fastapi" , "dev" , "--host" , "0.0.0.0" , "src/uv_docker_example" ]
0 commit comments