I'm trying to dockerize a simple script (a command line utility). Here is a working Dockerfile:
FROM python:3.9-slim
ARG user=tweaker project=tex-tweak src=tex_tweak
# Non-root user.
RUN useradd -ms /bin/bash "$user"
USER $user
WORKDIR /home/$user
ENV PATH=/home/$user/.local/bin:$PATH
# Source and project files.
RUN mkdir /home/$user/$project
WORKDIR /home/$user/$project
COPY $src ./$src/
COPY pyproject.toml ./
#COPY poetry.lock ./
# Build.
RUN pip install poetry --user && \
poetry config virtualenvs.create false && \
poetry install --no-dev && \
poetry build
CMD ["bash"]
Curiously, this is enough: the target utility somehow gets installed into .local/bin
; I can't see why.
python:slim
image is 115MB; the resulting image is 174MB. Not unacceptable, but relatively bloated. Multistage build is in order, u suppose. Unfortunately, I can't see how I should move the essentials into the second stage. The idea of selective copying of the .local/bin
and .local/lib
does not look particularly safe or inviting. Or maybe this is the way?
Or is it possible/advisable to pip install <target>.whl
into the second stage?