4 ms·
Docker "Using a virtual environment inside a Docker container is perhaps over-the-top, but it provides extra isolation from the base image’s own Python depende
by rekahrv 4y ago
Docker
"Using a virtual environment inside a Docker container is perhaps over-the-top, but it provides extra isolation from the base image’s own Python dependencies, and the entire /venv folder can be copied over between stages if you need."
Do you have some use cases in mind when this can be handy?
- gcarvalho 4y agoSay one of your dependencies has no pre-built wheels available, so you need gcc to build it from source in your docker image. You can apt install gcc in a build stage, install your dependency and then you don't need to bother clearing apt lists cache, pruning unneeded packages such as gcc and the packages that were installed alongside it, etc. Then, you create another stage for the final production runtime, copy the entire virtual environment over and that's it. In short, the virtual environment is easier to transport from one stage to another, compared to a non-isolated environment -- and that makes it easy to trim down the image size.