Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
February 24, 2021 12:35 pm GMT

Stop using virtualenv, pyenv, nvm, goenv and Use Docker images

Why I use Docker images

Image

Using version managers like pyenv and nvm are obsolete.

For example, virtualenv/pyenv only encapsulates Python dependencies.

Docker containers encapsulate an entire OS with several dependencies.

Docker already allows to pull several one-click images like python, nodejs, golang, etc ...

docker pull python:3.9.0
Enter fullscreen mode Exit fullscreen mode
# DockerfileFROM python:3.9.0
Enter fullscreen mode Exit fullscreen mode

Docker images and containers

image

A Docker image includes the elements needed to run an application as a container -- such as code, config files, environment variables, libraries and run time.

A Docker container can be seen as a replica or as a printout of that image.

For example, you can have one python image and multiple containers related to this image.

image

Isolation with the OS (Clean Install)

You may not have python installed on your OS and you can pull the python 3.9 docker image.

So you can only use python inside a docker container.

docker pull python:3.9.0
Enter fullscreen mode Exit fullscreen mode

You may have the python 2.7 installed on your OS and pull the python 3.9 docker image.

They will not conflict together, but you can only use python 3.9 inside a docker container.

If you don't want the python 3.9 anymore , you just have to delete the docker container related to the python 3.9 image and the python 3.9 image itself.

Multiple Versions

You can pull the python 2.7 docker image and the python 3.9 docker image.

They will not conflict together.

Multiple Layers

You can pull the python 2.9 docker image and install additional dependencies.

# DockerfileFROM python:3.9.0...COPY requirements.txt /app/requirements.txtRUN pip install -r requirements.txt
Enter fullscreen mode Exit fullscreen mode

Upgrade - Switch versions

You can pull the python 3.8 docker image and then switch to the 3.9 image.

# DockerfileFROM python:3.8.0 -> FROM python:3.9.0
Enter fullscreen mode Exit fullscreen mode

Example : python

# DockerfileFROM python:3.9.0
Enter fullscreen mode Exit fullscreen mode
# DockerfileFROM python:3.9.0-alpine
Enter fullscreen mode Exit fullscreen mode

Example : node

# DockerfileFROM node:14.16.0
Enter fullscreen mode Exit fullscreen mode
# DockerfileFROM node:14.16.0-alpine
Enter fullscreen mode Exit fullscreen mode

Hub

Links


Original Link: https://dev.to/javidjms/stop-using-virtualenv-pyenv-nvm-goenv-and-use-docker-images-40mn

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To