Skip to content

Instantly share code, notes, and snippets.

@stpettersens
Last active December 4, 2025 00:31
Show Gist options
  • Select an option

  • Save stpettersens/9a88c3f16376d8d164bf5d3118f513b9 to your computer and use it in GitHub Desktop.

Select an option

Save stpettersens/9a88c3f16376d8d164bf5d3118f513b9 to your computer and use it in GitHub Desktop.
Dockerfile to build Python 3.13.9 from source with an Alpine image.
# Dockerfile to build Python 3.13.9 from source with an Alpine image.
FROM alpine:latest
# Install build dependencies for python and git
RUN sed -i '2s/^# *//' /etc/apk/repositories
RUN apk update && apk add --no-cache build-base zlib-dev openssl-dev git
# Create python directory.
RUN mkdir -p /usr/build/python
WORKDIR /usr/build/python
# Test gcc installed.
RUN gcc --version
# Test make installed.
RUN make --version
# Test git installed.
RUN git --version
# Clone Python 3.13.9 from CPython git repository on GitHub and build it.
RUN git clone --depth 1 --branch v3.13.9 https://github.com/python/cpython
RUN cd cpython && git checkout v3.13.9
RUN cd cpython && ./configure --prefix=/opt/python/3.13.9 --enable-optimizations
RUN cd cpython && make -j$(nproc) PROFILE_TASK="" profile-opt
RUN cd cpython && make install
# Keep container running.
CMD [ "tail", "-f", "/dev/null" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment