Skip to content

Commit 24d5595

Browse files
committed
Docker: minimize size by using python-slim base image
1 parent 428dfc2 commit 24d5595

File tree

1 file changed

+33
-9
lines changed

1 file changed

+33
-9
lines changed

.devcontainer/Dockerfile

+33-9
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,49 @@
11
# https://github.com/devcontainers/images/tree/main/src/python
2-
FROM mcr.microsoft.com/devcontainers/python:1-3.13-bookworm
2+
#FROM mcr.microsoft.com/devcontainers/python:1-3.13-bookworm
3+
FROM python:3.13-slim-bookworm
4+
5+
# https://code.visualstudio.com/remote/advancedcontainers/add-nonroot-user
6+
ARG USERNAME=vscode
7+
ARG USER_UID=1000
8+
ARG USER_GID=$USER_UID
9+
10+
# Create the user
11+
RUN groupadd --gid $USER_GID $USERNAME \
12+
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME --shell /bin/bash \
13+
# [Optional] Add sudo support. Omit if you don't need to install software after connecting.
14+
&& apt-get update \
15+
&& apt-get install -y sudo \
16+
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
17+
&& chmod 0440 /etc/sudoers.d/$USERNAME
318

419
# Install additional packages.
5-
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
6-
# && apt-get -y install --no-install-recommends \
7-
# <your-package-list-here> \
8-
# && apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/*
20+
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
21+
&& apt-get -y install --no-install-recommends \
22+
git \
23+
make \
24+
&& apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/*
925

1026
# Install the project into `/app`
1127
WORKDIR /app
1228

1329
# Enable bytecode compilation
14-
ENV UV_COMPILE_BYTECODE=1
30+
ENV UV_COMPILE_BYTECODE=1 \
31+
UV_LINK_MODE=copy
1532

1633
# Install UV / UVX
1734
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
1835

1936
# Install project dependencies
20-
RUN --mount=type=bind,source=pyproject.toml,target=pyproject.toml \
21-
--mount=type=bind,source=uv.lock,target=uv.lock \
22-
uv sync --frozen --no-install-project --all-groups
37+
COPY pyproject.toml uv.lock ./
38+
RUN uv sync --frozen --no-install-project --all-groups \
39+
&& rm pyproject.toml uv.lock \
40+
&& chown -R $USERNAME:$USERNAME /app
2341

2442
# Place executables in the environment at the front of the path
2543
ENV PATH="/app/.venv/bin:$PATH"
44+
45+
# HACK: https://github.com/sphinx-doc/sphinx/issues/11739
46+
ENV LC_ALL=C.UTF-8
47+
48+
# [Optional] Set the default user. Omit if you want to keep the default as root.
49+
USER $USERNAME

0 commit comments

Comments
 (0)