I've been hacking at this for a couple hours now and I can't find an elegant way to use poetry to install dependencies inside of a Docker container (during build).
It either creates it's own virtualenv which is tricky to use when you're doing multistage or multi-base (docker compose) deployments. Or, if you supply a .venv it won't activate it properly and installs can fail.
RUN curl -sSL https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py | python
COPY ./pyproject.toml /app
COPY ./pyproject.lock /app
RUN python -m poetry install --no-interaction --allow-root-install
I propose a documented config setting along the lines of settings.virtualenvs.use_root true or a install flag which conveys this as an exception to the normal flow.
If you don't want poetry to automatically create virtualenvs you can set the settings.virtualenvs.create to false like so:
poetry config settings.virtualenvs.create false
This works! Thanks.
This does not work anymore as of poetry 0.12.1
@blakev can you share your Dockerfile?
@sdispater Can we get this reopened? Currently poetry doesn't have a satisfactory resolution for it, be that a flag or documentation for the existing way to do this. The setting is a bit too complicated currently because I don't know if I can include it in the pyproject.toml, or if I need to run it in Docker, or what...
I'm curious about the details of this statement from OP @blakev, even if a change is not made to poetry in relation to it :) As I am about to use poetry with virtualenv with multistage builds, probably.
It either creates it's own virtualenv which is tricky to use when you're doing multistage or multi-base (docker compose) deployments. Or, if you supply a
.venvit won't activate it properly and installs can fail.
I think use config seems not a good idea compare to directly pass command line options.
command-line-option is more self-explain, more close to where it was really used. And more convention while using in gitlab-ci or docker build, which will need only one command instead of two.
And who would like to keep a config file in gitlab CI worker or docker images??
anyway even if some command line tool use config file, they will provide command line option to override the default config as a choices.
how ever the poetry seems high depend on config file and not provide equal command option, which make it something hard to use and hard to find the solution.
Amazing how this has come full circle, since I ran into this issue AGAIN today.
This is the way to solve it,
RUN POETRY_VIRTUALENVS_CREATE=false poetry install
Most helpful comment
If you don't want
poetryto automatically create virtualenvs you can set thesettings.virtualenvs.createtofalselike so: