25
submitted 2 months ago* (last edited 2 months ago) by alexdeathway@programming.dev to c/python@programming.dev

I read some articles about using a virtual environment in Docker. Their argument are that the purpose of virtualization in Docker is to introduce isolation and limit conflicts with system packages etc.

However, aren't Docker and Python-based images (e.g., python:*) already doing the same thing?

Can someone eli5 this whole thing?

you are viewing a single comment's thread
view the rest of the comments
[-] fubarx@lemmy.ml 3 points 2 months ago

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.

[-] uthredii@programming.dev 2 points 2 months ago

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.

load more comments (3 replies)
this post was submitted on 04 Sep 2024
25 points (90.3% liked)

Python

6339 readers
7 users here now

Welcome to the Python community on the programming.dev Lemmy instance!

📅 Events

PastNovember 2023

October 2023

July 2023

August 2023

September 2023

🐍 Python project:
💓 Python Community:
✨ Python Ecosystem:
🌌 Fediverse
Communities
Projects
Feeds

founded 1 year ago
MODERATORS