gpt4 book ai didi

django - 复制失败: stat/var/lib/docker/tmp/docker-builder/server/requirements. txt:没有这样的文件或目录

转载 作者:行者123 更新时间:2023-12-02 18:01:57 25 4
gpt4 key购买 nike

似乎是某种上下文问题。我试图弄清楚为什么在使用 Skaffold 启动本地 Kubernetes 集群时这可以正常工作,但在推送到 Azure 时却无法正确构建镜像。

基本结构是:

test-app/
server/
requirements.txt
Dockerfile
azure-pipeline.yml
skaffold.yaml

我的生产server/Dockerfile如下:

FROM python:3.7-slim
ENV PYTHONUNBUFFERED 1
WORKDIR '/app'
EXPOSE 5000
COPY ./server/requirements.txt .
RUN pip install -r requirements.txt
COPY ./server .
CMD ["python", "manage.py", "collectstatic"]
CMD ["gunicorn", "-b", ":5000", "--log-level", "info", "config.wsgi:application"]

我正在使用在 Azure DevOps 的管道部分中为我生成的 azure-pipelines.yml:

# Docker
# Build and push an image to Azure Container Registry
# https://learn.microsoft.com/azure/devops/pipelines/languages/docker

trigger:
- master

resources:
- repo: self

variables:
# Container registry service connection established during pipeline creation
dockerRegistryServiceConnection: '<connection-string>'
imageRepository: 'testapp'
containerRegistry: 'testappcontainers.azurecr.io'
dockerfilePath: '$(Build.SourcesDirectory)/server/Dockerfile'
tag: '$(Build.BuildId)'

# Agent VM image name
vmImageName: 'ubuntu-latest'

stages:
- stage: Build
displayName: Build and push stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
steps:
- task: Docker@2
displayName: Build and push an image to container registry
inputs:
command: buildAndPush
repository: $(imageRepository)
dockerfile: $(dockerfilePath)
containerRegistry: $(dockerRegistryServiceConnection)
tags: |
$(tag)

在自动构建期间,它会到达 COPY ./server/requirements.txt 。 并在标题中抛出错误。

阅读this question ,我尝试了一些建议的解决方案,但没有解决,例如:

COPY ./server/requirements.txt /app
COPY server/requirements.txt /app

另外,我也刚刚尝试过:

COPY requirements.txt /app

仍然出现错误。

所以,有点难住了:

  1. 如何解决此问题,以便在 Pipelines 中正确构建并推送到 CRS...
  2. 如果这是上下文问题,为什么在使用 Skaffold 时本地开发中不会出现问题
<小时/>

实际上,example project具有类似的项目结构:

pipelines-javascript-docker/
app/
Dockerfile

它运行良好......有些我可能明显忽略了一些东西。

最佳答案

当我遇到这个障碍时,我通过在 yml 文件中设置属性 buildContext 来解决。

- task: Docker@2
displayName: Build and push an image to container registry
inputs:
containerRegistry: '$(ACR.Connector)'
repository: '$(imageName)'
command: 'buildAndPush'
Dockerfile: '$(Agent.BuildDirectory)/s/server/Dockerfile'
buildContext: '$(Agent.BuildDirectory)/s'
tags: '$(tag)'

关于django - 复制失败: stat/var/lib/docker/tmp/docker-builder<num>/server/requirements. txt:没有这样的文件或目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59256220/

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