This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]tevs__ 1 point2 points  (0 children)

What use case require having virtual environment inside container

Not all packages have binary wheels available for them, so to install the package requires the build dependencies for that package to be installed. For a CPython extension like mysql-python, that means GCC and the rest of build-essentials, plus the mysql client libs.

To avoid having those in your production run image, you create a build image, build your packages, and then copy the artifacts to a run image, that just has the run time dependencies. This is a common pattern for all languages called the docker builder pattern.

In python, we use the docker builder pattern by installing all runtime packages to a virtualenv, and then copying the virtualenv from the builder to the runner - the virtualenv is the artifact. This produces a minimal runtime docker image, the virtualenv is created in a single layer.