DEV Community

loading...
Cover image for Do you use python virtualenv inside Docker at production?

Do you use python virtualenv inside Docker at production?

ashraful profile image Ashraful Islam ・1 min read

Do you ship your container dev to the stage, stage to prod? OR, clone the repo at production server and run docker command, like, docker-compose up --build

Discussion (15)

pic
Editor guide
Collapse
defman profile image
Sergey Kislyakov πŸ‡·πŸ‡Ί πŸ‡ΊπŸ‡Έ

No. I don't see any benefits for that. Docker container is already a virtual environment itself, not sure why I'd want to have another one inside it.

Collapse
ashraful profile image
Ashraful Islam Author

Do you ship your container dev to stage, stage to prod. OR, clone the repo at production server and run docker command, like, docker-compose up

Collapse
defman profile image
Sergey Kislyakov πŸ‡·πŸ‡Ί πŸ‡ΊπŸ‡Έ

CD does delivery to staging, once we're good with it, it's simply a click on a button to release it and ship to prod.

Collapse
ashraful profile image
Ashraful Islam Author

That's a good and valid point. Thank you

Collapse
lietux profile image
Janne "Lietu" Enberg

It's great when doing a multi-stage build on Alpine Linux - install your build dependencies, build your dependencies to a .venv and then copy that from the build container to the actual runtime environment.

Helps both you stage your Dockerfiles correctly for optimal build times, and with the end results cleaner and not having to worry about leaving C compilers etc. lying around.

Collapse
lietux profile image
Janne "Lietu" Enberg

Automated pipelines ftw. Have push to master trigger tests + builds + deployment automatically.

Collapse
hseritt profile image
Harlin Seritt

Great question! I will use pyenv (which comes with pieces to work with virtualenv) as it makes it easy to extend docker containers should I need to upgrade Python itself or any of its packages. But, as someone pointed out, docker itself is a virtual environment. So, if it makes sense for you to use a Python virtualenv then go for it. But, if it's not necessary for the particular container, there's no reason that you must use one.

Collapse
marounmaroun profile image
Maroun Maroun

I don't like to have difference between my development setup and the production setup (containerized). I don't find it harmful to have a virtual env inside the container.

Collapse
ashraful profile image
Ashraful Islam Author

Do you ship your container dev to stage, stage to prod. OR, clone the repo at production server and run docker command, like, docker-compose up

And thanks for your thought.

Collapse
marounmaroun profile image
Maroun Maroun

We actually use K8s for dev, staging and production clusters. For development, we have containers that're orchestrated by docker-compose.

The flow is: Test things locally, once done, deploy to dev, then move to staging and finally deploy on production.

Collapse
hseritt profile image
Harlin Seritt

Says it better than I could have. +1

Collapse
juancarlospaco profile image
Juan Carlos

No virtualenv, no Docker.

Collapse
ashraful profile image
Ashraful Islam Author

Didn’t get your point. Can you please say a little bit more?

Collapse
juancarlospaco profile image
Juan Carlos

I do not use virtualenv, nor Docker.
:)

Thread Thread
ashraful profile image
Ashraful Islam Author

Ok then. Probably you could skip this discussion. Btw, thanks