soc*_*pet 5 django azure docker azure-devops azure-container-service
似乎是某种上下文问题。我试图弄清楚为什么在使用 Skaffold 启动本地 Kubernetes 集群时效果很好,但在推送到 Azure 时却无法正确构建映像。
基本结构是:
test-app/
server/
requirements.txt
Dockerfile
azure-pipeline.yml
skaffold.yaml
Run Code Online (Sandbox Code Playgroud)
我的制作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"]
Run Code Online (Sandbox Code Playgroud)
我正在使用azure-pipelines.yml在 Azure DevOps 的 Pipelines 部分中为我生成的:
# 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)
Run Code Online (Sandbox Code Playgroud)
在自动构建过程中,它会COPY ./server/requirements.txt .在标题中抛出错误。
阅读这个问题,我尝试了一些建议的解决方案但没有解决方案,例如:
COPY ./server/requirements.txt /app
COPY server/requirements.txt /app
Run Code Online (Sandbox Code Playgroud)
另外,我也刚刚尝试过:
COPY requirements.txt /app
Run Code Online (Sandbox Code Playgroud)
仍然收到错误。
所以,有点难住了:
实际上,示例项目具有类似的项目结构:
pipelines-javascript-docker/
app/
Dockerfile
Run Code Online (Sandbox Code Playgroud)
它运行良好......有些我可能明显忽略了一些东西。
在更仔细地查看示例项目(该项目与我想要做的结构相同)之后,我最终复制了其Dockerfile格式。我最终得到了这个,效果很好:
FROM python:3.7-slim
ENV PYTHONUNBUFFERED 1
WORKDIR /app
EXPOSE 5000
COPY requirements*.txt ./
RUN pip install -r requirements.txt
COPY . .
CMD ["python", "manage.py", "collectstatic"]
CMD ["gunicorn", "-b", ":5000", "--log-level", "info", "config.wsgi:application"]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9835 次 |
| 最近记录: |