A
A
albertalexandrov2021-07-22 14:22:27
Python
albertalexandrov, 2021-07-22 14:22:27

Copy installed poetry packages from slim image to alpine image and run?

I intend to build the libraries in the slim image and then put them in alpine. Dockerfile is written for this:

FROM python:3.8.7-slim AS builder

ENV POETRY_VIRTUALENVS_CREATE=false
WORKDIR /app
RUN apt-get update
RUN apt-get install -y build-essential
RUN apt-get install -y libldap2-dev  # для python-ldap
RUN apt-get install -y libsasl2-dev  # для python-ldap
COPY poetry.lock pyproject.toml ./
RUN python -m pip install --upgrade pip && pip install poetry && poetry install --no-dev

FROM python:3.8.7-alpine3.13 AS runtime
COPY --from=builder /root/* /root/
WORKDIR /app
COPY pythonapline .
#RUN python manage.py makemigrations && python manage.py migrate
EXPOSE 8000
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]


poetry by default creates a virtual environment in ~/.cache/pypoetry/virtualenvs (Linux). To make it into the runtime image, the contents of the /root folder from the builder image are copied to the /root folder of the runtime image.

However, when I run the image, I get import errors. Apparently, it is necessary to activate the virtual environment?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2021-07-22
@dmtrrr

Why not build directly on the basis of alpine?
The virtual environment doesn't do any special magic, read about https://docs.python.org/3/using/cmdline.html#envva...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question