linux 构建python映像时出现Docker合成问题,访问被拒绝或存储库不存在

t2a7ltrp  于 2022-11-02  发布在  Linux
关注(0)|答案(1)|浏览(220)

我正在尝试排除Windows 10上udemy教程的故障,但为什么我的合成文件无法运行。我尝试重新登录Docker,我能够成功运行Docker build python:3.9-slim-bullseye。这里有人看到我的问题并帮助我了解发生了什么吗?
我想我的问题跟那句台词有关系:

apt-get update && apt-get install --no-install-recommends -y \
    build-essential \
    libpq-dev

教程是original code is here on his github,但我的大部分代码都是直接从他那里拷贝过来的。

本地.yml文件

version: "3.9"

services:
  api:
    build:
      context: .
      dockerfile: docker/local/django/Dockerfile
    command: /start
    container_name: django-api
    volumes:
      - .:/app
      - static_volume:/app/staticfiles
      - media_volume:/app/mediafiles
    ports:
      - "8000:8000"
    env_file:
      - ./.envs/.local/.django
      - ./.envs/.local/.postgres
    depends_on:
      - postgres
      - mailhog
    networks:
      - authors-api-live

  postgres:
    build:
      context: .
      dockerfile: ./docker/local/postgres/Dockerfile
    container_name: postgres
    # volumes:  # This is also causing issues
    #     - local_postgres_data:/var/lib/postgresql/data
    #     - local_postgres_data_backups:/backups
    env_file:
        - ./.envs/.local/.postgres
    networks:
        - authors-api-live

  mailhog:
    image: mailhog/mailhog:v1.0.0
    container_name: mailhog
    ports:
      - "8025:8025"
    networks:
      - authors-api-live

networks:
  authors-api-live:
    driver: bridge

volumes:
  local_postgres_data_backups: {}
  static_volume:
  media_volume:

Django 嵌入文件

ARG PYTHON_VERSION=3.9-slim-bullseye

FROM python:${PYTHON_VERSION} as python

# BUILD STAGE

FROM python as pthyon-build-stage
ARG BUILD_ENVIORMENT=local

RUN apt-get update && apt-get install --no-install-recommends -y \
    build-essential \
    libpq-dev

COPY ./requirements . 

RUN pip wheel --wheel-dir /usr/src/app/wheels \
    -r ${BUILD_ENVIORMENT}.txt

# RUN STAGE

FROM python as python-run-stage

ARG BUILD_ENVIORMENT=local

# ARG APP_HOME=/usr/src/app

ARG APP_HOME=/app

ENV PYTHONDONTWRITEBYTECODE 1

ENV UNBUFFERED 1

ENV BUILD_ENVIORMENT=${BUILD_ENVIORMENT}

WORKDIR ${APP_HOME}

RUN apt-get update && apt-get install --no-install-recommends -y \
    libpq-dev \
    gettext \
    && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
    && rm -rf /var/lib/apt/lists/*

# use wheels to make installation faster

COPY --from=python-build-stage /usr/src/app/wheels /wheels/

RUN pip install --no-cache-dir --no-index --find-links=/wheels/ /wheels/* \
    && rm -rf /wheels/

# Copy in entrypoint to test connection to database

COPY ./docker/local/django/entrypoint /entrypoint
RUN sed -i 's/\r$//g' /entrypoint
RUN chmod +x /entrypoint

# check if models are migrated

COPY ./docker/local/django/start /start
RUN sed -i 's/\r$//g' /start
RUN chmod +x /start

# COPY ./docker/local/django/celery/worker/start /start-celeryworker

# RUN sed -i 's/\r$//g' /start-celeryworker

# RUN chmod +x /start-celeryworker

# COPY ./docker/local/django/celery/flower/start /start-flower

# RUN sed -i 's/\r$//g' /start-flower

# RUN chmod +x /start-flower

COPY . ${APP_HOME}

ENTRYPOINT ["/entrypoint"]

错误消息:

PS C:\Users\...\MasterDjangoRESTFrameworkWithDocker\authors-haven-api\authors-src> docker-compose -f local.yml up -d --remove-orphans   
Building api
[+] Building 1.2s (9/18)
 => [internal] load build definition from Dockerfile                                                                                                       0.1s 
 => => transferring dockerfile: 32B                                                                                                                        0.0s 
 => [internal] load .dockerignore                                                                                                                          0.1s 
 => => transferring context: 34B                                                                                                                           0.0s 
 => [internal] load metadata for docker.io/library/python:3.9-slim-bullseye                                                                                0.0s 
 => [internal] load build context                                                                                                                          0.2s 
 => => transferring context: 5.14kB                                                                                                                        0.1s 
 => [python 1/1] FROM docker.io/library/python:3.9-slim-bullseye                                                                                           0.0s 
 => ERROR FROM docker.io/library/python-build-stage:latest                                                                                                 0.9s
 => => resolve docker.io/library/python-build-stage:latest                                                                                                 0.9s 
 => CACHED [python-run-stage  1/11] WORKDIR /app                                                                                                           0.0s 
 => CANCELED [python-run-stage  2/11] RUN apt-get update && apt-get install --no-install-recommends -y     libpq-dev     gettext     && apt-get purge -y   1.0s 
 => [auth] library/python-build-stage:pull token for registry-1.docker.io                                                                                  0.0s 
------
 > FROM docker.io/library/python-build-stage:latest:
------
failed to load cache key: pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed  
ERROR: Service 'api' failed to build : Build failed
cu6pst1q

cu6pst1q1#

看起来在您分配构建阶段名称的行上有一个打字错误。

FROM python as pthyon-build-stage

将此更改为:

FROM python as python-build-stage

并且构建阶段的命名应该与后面阶段的命名一致。

相关问题