pipenv - docker的系统选项。在docker中获取所有python包的建议方法是什么?

问题描述 投票:0回答:1

我使用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中恢复我的环境

python django docker pipenv
1个回答
1
投票

一个典型的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

© www.soinside.com 2019 - 2024. All rights reserved.