Fix Python – What’s the difference between Docker and Python virtualenv?

Question

Asked By – danielschnoll

From what I understand about Docker, it’s a tool used for virtual environments. In their lingo, its called “containerization”. This is more or less what Python’s virtualenv does. However, you can use virtualenv in Docker. So, is it a virtual environment inside a virtual environment? I’m confused as to how this would even work, so could someone please clarify?

Now we will see solution for issue: What’s the difference between Docker and Python virtualenv?


Answer

A virtualenv only encapsulates Python dependencies. A Docker container encapsulates an entire OS.

With a Python virtualenv, you can easily switch between Python versions and dependencies, but you’re stuck with your host OS.

With a Docker image, you can swap out the entire OS – install and run Python on Ubuntu, Debian, Alpine, even Windows Server Core.

There are Docker images out there with every combination of OS and Python versions you can think of, ready to pull down and use on any system with Docker installed.

This question is answered By – sp0gg

This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0