Install Python on Alpine Linux - Docker

Install Python on Alpine Linux - Docker

In order to install Python on Alpine Linux the smallest and most security-oriented Linux distribution mostly used with Docker, you will need to make use of the apk - the alpine package manager.

% docker run -it --name python-with-alpine alpine

# apk add python3
(1/13) Installing libbz2 (1.0.8-r1)
(2/13) Installing expat (2.4.8-r0)
(3/13) Installing libffi (3.4.2-r1)
(4/13) Installing gdbm (1.23-r0)
(5/13) Installing xz-libs (5.2.5-r1)
(6/13) Installing libgcc (11.2.1_git20220219-r2)
(7/13) Installing libstdc++ (11.2.1_git20220219-r2)
(8/13) Installing mpdecimal (2.5.1-r1)
(9/13) Installing ncurses-terminfo-base (6.3_p20220521-r0)
(10/13) Installing ncurses-libs (6.3_p20220521-r0)
(11/13) Installing readline (8.1.2-r0)
(12/13) Installing sqlite-libs (3.38.5-r0)
(13/13) Installing python3 (3.10.5-r0)
Executing busybox-1.35.0-r17.trigger
OK: 57 MiB in 27 packages
# python3 --version
Python 3.10.5

You can also get it installed using the RUN instruction in a Dockerfile,

Python3 on Alpine Linux using Dockerfile

FROM alpine:latest
RUN apk add python3
CMD python3 --version
% docker build -t alpine-python .
% docker run -it alpine-python
Python 3.10.5

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail:

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap