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:
alpine
does not have a python package. Instead, it ships apython3
package instead.- The
python
installation does not includepip
. It is another standalone package calledpy3-pip
python3
package doesn’t addpython
to the path (it addspython3
instead), butpy3-pip
does addpip
to 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