this post was submitted on 04 Sep 2024
24 points (90.0% liked)

Python

6229 readers
23 users here now

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

📅 Events

October 2023

November 2023

PastJuly 2023

August 2023

September 2023

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

founded 1 year ago
MODERATORS
 

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
[–] bjorney@lemmy.ca 10 points 2 weeks ago* (last edited 2 weeks ago) (7 children)

It's not necessary but there is no reason not to.

Pros:

  • production and development programs are more similar
  • upgrading your base image won't affect your python packages
  • you can use multi stage builds to create drastically smaller final images

Cons:

  • you have to type venv/bin/python3 instead of just python3 in the run line of your dockerfile
[–] dwt@feddit.org 3 points 2 weeks ago

It’s easy to set the path to include the venv in the Dockerfile, that way you never have to activate, either in the run line, nor if you exec into it. Also this makes all your custom entry points super easy to use. Bonus, it’s super easy to use uv to get super fast image builds like that. See this example https://gist.github.com/dwt/6c38a3462487c0a6f71d93a4127d6c73

load more comments (6 replies)