Context
I need to add a python package to an existing docker alpine image.
Solution
There is a couple of caveats with the solution, which I share below:
alpinedoes not have a python package. Instead, it ships apython3package instead.- The
pythoninstallation does not includepip. It is another standalone package calledpy3-pip python3package doesn’t addpythonto the path (it addspython3instead), butpy3-pipdoes addpipto the path.
A simplified Dockerfile, looks like:
FROM image:alpine
RUN apk update && apk add --update --no-cache \
python3 \ #Install the latest version of python 3
py3-pip && \ # Installs pip since it isn't packaged with python
ln -sf python3 /usr/bin/python # Makes 'python' available in path
WORKDIR terraform
COPY ./requirements.txt ./
RUN pip install -r requirements.txt