我使用pipenv
作为我的django
应用程序。
$ mkdir djangoapp && cd djangoapp
$ pipenv install django==2.1
$ pipenv shell
(djangoapp) $ django-admin startproject example_project .
(djangoapp) $ python manage.py runserver
现在我转向停靠者环境。
根据我的理解,pipenv
只在virtualenv
内安装包
您不需要容器内的virtualenv,docker容器本身就是一个虚拟环境。
经过许多Dockerfile的后来我发现--system
选项安装在系统中。
例如,我发现以下内容:
https://testdriven.io/blog/dockerizing-django-with-postgres-gunicorn-and-nginx/
COPY ./Pipfile /usr/src/app/Pipfile
RUN pipenv install --skip-lock --system --dev
https://hub.docker.com/r/kennethreitz/pipenv/dockerfile
# -- Install dependencies:
ONBUILD RUN set -ex && pipenv install --deploy --system
https://wsvincent.com/beginners-guide-to-docker/
# Set work directory
WORKDIR /code
# Copy Pipfile
COPY Pipfile /code
# Install dependencies
RUN pip install pipenv
RUN pipenv install --system
所以--system
只是足够或--deploy --system
是更好的方式。和--skip-lock --system --dev
再次不同。
那么有人可以指导如何在Docker中恢复我的环境
一个典型的Docker部署将涉及一个requirements.txt
(它是一个file where you can store your pip dependencies, including Django itself)文件,然后在你的Dockerfile
你做的事情,如:
FROM python:3.7 # or whatever version you need
ADD requirements.txt /code/
WORKDIR /code
# install your Python dependencies
RUN pip install -r requirements.txt
# run Django
CMD [ "python", "./manage.py", "runserver", "0.0.0.0:8000"]
您根本不需要pipenv
,因为您不再拥有虚拟环境。
更好的是,你可以在docker-compose.yml
文件中配置很多东西,然后使用docker-compose
来运行和管理你的服务,而不仅仅是Django。
Docker have a very good tutorial on dockerising Django与它。如果你不确定Dockerfile
本身发生了什么,check the manual。