Docker Community Forums

Share and learn in the Docker community.

Bests practices around docker and python environment

I’m a newbie on Docker, and I’ll have to host multiple application on several containers in my work. What I wanted to know is : should I create a virtual environment for each container (with only the python library needed for the API created for example) or should I create one big virtual environment that I’ll have to install on every container ? Or is it possible that one container host multiples application ?
I tried to find some of the bests practices around this, but couldn’t find something very clear.

In advance, thank you.


The point of a container is having a little as possible pr image.
So if you have an application that only needs 10 modules, then you should only install those 10 modules.

Just in case you havnt noticed, the offcial python image on Docker Hub

have an example of using requirements in a dockerfile:

FROM python:3

WORKDIR /usr/src/app

COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt

COPY . .

CMD [ "python", "./" ]