gpt4 book ai didi

python - Docker 安装 pip 要求时速度太慢

转载 作者:行者123 更新时间:2023-12-02 06:59:05 26 4
gpt4 key购买 nike

我正在尝试为虚拟本地 Django 项目实现一个 docker。我使用 docker-compose 作为定义和运行多个容器的工具。这里我尝试将 Django-web-app 和 PostgreSQL 两个服务容器化。

Dockerfiledocker-compose.yml 中使用的配置

Dockerfile

# Pull base image
FROM python:3.7-alpine

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# Set work directory
WORKDIR /code

# Install dependencies
COPY requirements.txt /code/
RUN pip install -r requirements.txt

# Copy project
COPY . /code/

docker-compose.yml

version: '3.7'

services:
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- "8000:8000"
depends_on:
- db
db:
image: postgres:11
volumes:
- postgres_data:/var/lib/postgresql/data/
volumes:
postgres_data:

一切似乎都还好。 postgres 集成的路径以及除一件事 pip install -rrequirements.txt 之外的所有路径。根据要求进行安装需要花费太多时间。上次我放弃了这个,但最终安装完成了,但需要很多时间才能完成。

在我的场景中,唯一的问题是为什么pip install如此慢。如果我缺少什么?我是 docker 的新手,非常感谢有关此主题的任何帮助。谢谢。

我正在关注这个Link .

最佳答案

这可能是因为 PyPI 轮子不适用于 Alpine。 Alpine 不使用预编译文件,而是下载源代码并进行编译。尝试使用 python:3.7-slim 图像代替:

# Pull base image
FROM python:3.7-slim

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# Set work directory
WORKDIR /code

# Install dependencies
COPY requirements.txt /code/
RUN pip install -r requirements.txt

# Copy project
COPY . /code/

查看这篇文章了解更多详细信息:Alpine makes Python Docker builds 50× slower .

关于python - Docker 安装 pip 要求时速度太慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60086741/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com