By default, Poetry will install virtual environment in the venvs directory in the subdirectory with hashed name, e.g. apex-q4124gfga.py3.6
.
I wanted to create a virtual environment in Docker multi-stage build so it can be copied in the other stage with single command. For that I needed that the name is known beforehand.
To fix this, I used an approach described here:
If you are trying to control the virtual environment path in a Dockerfile, the canonical method is:
Setting
PATH
andVIRTUAL_ENV
has the effect of activating the virtual environment and causing all followingRUN
lines to use that environment; all yourpoetry
andpython
commands will ‘just work.‘
My code:
When analyzing with Docker Dive the packages were indeed installed properly in the specified directory /opt/.venv
: