this post was submitted on 04 Sep 2024
25 points (90.3% liked)

Python

6327 readers
231 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
 

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
[โ€“] [email protected] 10 points 2 months ago* (last edited 2 months 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
[โ€“] uthredii 2 points 1 month ago (3 children)

upgrading your base image wonโ€™t affect your python packages

Surely if upgrading python will affect your global python packages it will also affect your venv python packages?

you can use multi stage builds to create drastically smaller final images

This can also be done without using venv's, you just need to copy them to the location where global packages are installed.

[โ€“] sweng 3 points 1 month ago (2 children)

Upgrading the base image does not imply updating your python, and even updating your python does not imply updating your python packages (except for the standard libraries, of course).

[โ€“] uthredii 1 points 1 month ago (1 children)

Sure, but in the case where you upgrade python and it affects python packages it would affect global packages and a venv in the same way.

[โ€“] sweng 1 points 1 month ago

Sure If that happens. But it may also not. Which is actually usually the case. Sure, it's not 100% safe, but it is safer.

load more comments (3 replies)