Medium article: [Blazing fast Python Docker builds with Poetry](https://medium.com/@albertazzir/blazing-fast-python-docker-builds-with-poetry-a78a66f5aed0)
## Install deps only with --no-root
This allows to cache installed dependencies separately from the project.
## Install deps in a separate layer
```
ENV POETRY_CACHE_DIR /tmp/poetry_cache
COPY pyproject.toml poetry.lock README.md ./
RUN --mount=type=cache,target=$POETRY_CACHE_DIR poetry install --no-root --no-directory
COPY . .
RUN --mount=type=cache,target=$POETRY_CACHE_DIR poetry install
```
## Create virtualenvs in /opt/virtualenvs
This enables mounting the project directory as a volume without overriding the virtualenvs.
```
RUN poetry config virtualenvs.create true && \
poetry config virtualenvs.in-project false && \
poetry config virtualenvs.path /opt/virtualenvs
```
#docker #poetry