Django 使用docker时是否需要使用虚拟环境?

Django 使用docker时是否需要使用虚拟环境?,django,docker,virtualenv,Django,Docker,Virtualenv,我不知道Docker比虚拟环境有什么好处。是否需要同时使用虚拟环境和docker 在今天之前,我基本上使用虚拟环境来包装Django项目。但是今天我的朋友推荐我使用docker。我不知道该用什么 我使用这个命令来创建虚拟环境 python3-mvenv虚拟环境名称 这是创建虚拟环境的最佳方法还是我应该使用另一种方法来创建虚拟环境我宁愿在本地开发环境中使用pipenv来替换virtualenv,而在生产环境中使用docker来替换虚拟环境。这是我的Dockerfile(使用gunicorn运行dj

我不知道Docker比虚拟环境有什么好处。是否需要同时使用虚拟环境和docker

在今天之前,我基本上使用虚拟环境来包装Django项目。但是今天我的朋友推荐我使用docker。我不知道该用什么

我使用这个命令来创建虚拟环境
python3-mvenv虚拟环境名称

这是创建虚拟环境的最佳方法还是我应该使用另一种方法来创建虚拟环境

我宁愿在本地开发环境中使用pipenv来替换virtualenv,而在生产环境中使用docker来替换虚拟环境。这是我的Dockerfile(使用gunicorn运行django):

FROM python:3.6

ENV PYTHONUNBUFFERED 1

# switch system download source
RUN python -c "s='mirrors.163.com';import re;from pathlib import Path;p=Path('/etc/apt/sources.list');p.write_text(re.sub(r'(deb|security)\.debian\.org', s, p.read_text()))"
RUN apt-get update

# aliyun source for pip
RUN python -c "s='mirrors.aliyun.com';from pathlib import Path;p=Path.home()/'.pip';p.mkdir();(p/'pip.conf').write_text(f'[global]\nindex-url=https://{s}/pypi/simple\n[install]\ntrusted-host={s}\n')"

# Optional: install and conf vim, install ipython
RUN apt-get install -y vim
RUN wget https://raw.githubusercontent.com/waketzheng/carstino/master/.vimrc
RUN pip install ipython

# copy source code to docker image
WORKDIR /carrot
ADD . .

# required packages for carrot
RUN apt-get install -y ruby-sass

# install gunicorn and Pipfile
RUN pip install pipenv gunicorn
RUN pipenv install --system
RUN python manage.py collectstatic --noinput

# database name and rpc server ip
ENV POSTGRES_HOST=db
ENV RPC_SERVER_IP=172.21.0.2

EXPOSE 9000

# the PASSWORD env should be replace to a real one
CMD ["gunicorn", "--bind", ":9000", "--env", "PASSWORD=123456", "--error-logfile", "gunicorn.error", "--log-file", "gunicorn.log", "carrot.wsgi:application"]