25
ELI5 Using python virtual environment in docker container.
(programming.dev)
Welcome to the Python community on the programming.dev Lemmy instance!
Past
November 2023
October 2023
July 2023
August 2023
September 2023
I can think of only two reasons to have a venv inside a container:
If you're running third-party services inside a container, pinned to different Python versions.
If you do local development without docker and scripts that have to activate the venv from inside the script. If you move the scripts inside the container, now you don't have a venv. But then it's easy to just check an environment variable and skip, if inside Docker.
For most applications, it seems like an unnecessary extra step.
If you do multi stage builds (example here) it is slightly easier to use venvs.
If you use the global environment you need to hardcode the path to global packages. This path can change when base images are upgraded.