python - 服务 'web' 无法构建,协议(protocol)错误

标签 python django docker docker-compose dockerfile

我正在尝试在 docker 容器中使用 postgresql。但是,我收到错误

Service 'web' failed to build: The command '/bin/sh -c apk add --update --no-cache --virtual .tmp-build-deps gcc libc-dev linux-headers postgresql-dev musl-dev zlib zlib-dev' returned a non-zero code: 4

我遇到其他相关问题,例如错误:mpfr3-3.1.5-r1:协议(protocol)错误。

这是一个问题的屏幕截图,这可能彼此相关

enter image description here

这是代码

Dockerfile

FROM python:3.7-alpine

ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE 1

# set working directory which will be inside ubuntu
WORKDIR /code

#### Install a dependency ####
# Copies new files and resources to the image's filesystems
RUN pip3 install pipenv
COPY Pipfile Pipfile.lock /code/
RUN apk add --update --no-cache postgresql-client jpeg-dev
RUN apk add --update --no-cache --virtual .tmp-build-deps \
    gcc libc-dev linux-headers postgresql-dev musl-dev zlib zlib-dev
RUN pipenv install --system
RUN apk del .tmp-build-deps
COPY . /code/

RUN adduser -D user
USER user

docker-compose.yml

version: "3.7"

services:
  db:
    image: postgres:12-alpine
    environment:
      - POSTGRES_DB=database
      - POSTGRES_USER=admin
      - POSTGRES_PASSWORD=admin123
  web:
    build: .
    command: >
      sh -c "python /code/manage.py wait_for_db &&
             python /code/manage.py runserver 0.0.0.0:8000"
    environment:
      - DB_HOST=db
      - DB_NAME=database
      - DB_USER=admin
      - DB_PASS=admin123
    volumes:
      - .:/code
    # lets us map our port 8000 to the port 8000 in the Docker container
    ports:
      - 8000:8000
    # it says that we should run the db first before running our web services
    depends_on:
      - db

最佳答案

听起来好像找不到存储库。在运行 apk add 命令之前添加此行。

RUN echo "http://dl-cdn.alpinelinux.org/alpine/v3.7/main" >> /etc/apk/repositories

编辑:另外,您在 docker-compose.yml 中指向上面的 Dockerfile 的位置

关于python - 服务 'web' 无法构建,协议(protocol)错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56503035/

相关文章:

python - 无法使用 Mixin 类扩展 python IntEnum

python - 为什么Python中协方差函数的输出差异太大?

python - 使用python脚本远程访问Django中的sqlite3

javascript - 如何使用 Ajax 从 Django 捕获 PermissionDenied(403)?

docker - 我应该如何使用主机而不是服务名称连接到容器?

python - 如何解决 Docker 镜像中的 Tesseract "Failed loading language ' eng'"问题

python - n 个列表中项目的所有可能组合

django - 在 AWS 上使用 django 的 ssl

c# - RavenDb - 状态代码 : NotFound

docker - 为什么 docker 无法将/bin/sh -c 识别为有效的入口点?