首页 > 解决方案 > Azure DevOps docker build 与本地构建产生不同的结果

问题描述

我有一个使用 create-react-app 启动器构建的 React 应用程序。我正在尝试将此应用程序部署到 Azure App 服务。在本地测试时,一切都按预期工作。当我使用通过管道推送到 ACR 的图像来部署它时,应用程序的行为有所不同,并且出现了本地未见的错误。当我在本地构建映像并将其推送到 ACR 存储库时,问题就消失了。因此,构建管道会导致不同的行为。任何想法如何解决这样的问题?

这是我正在使用的 Dockerfile:

# build environment
FROM node:13.12.0-alpine as build
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
COPY package.json ./
COPY package-lock.json ./
RUN npm ci --silent
RUN npm install react-scripts@3.4.1 -g --silent
COPY . ./
RUN npm run build

# production environment
FROM nginx:stable-alpine
COPY --from=build /app/build /usr/share/nginx/html
# new
COPY nginx/nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

这是 ADO 中的构建定义:

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

trigger:
- master

resources:
- repo: self

variables:
  # Container registry service connection established during pipeline creation
  dockerRegistryServiceConnection: '3919c5b1-8ce6-4f6c-aa87-73632208d6a2'
  imageRepository: 'videoeffectsreact'
  containerRegistry: 'videoeffects.azurecr.io'
  dockerfilePath: '$(Build.SourcesDirectory)/Dockerfile'
  tag: '$(Build.BuildId)'
  
  # Agent VM image name
  vmImageName: 'ubuntu-18.04'

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)
          latest
  

标签: reactjsazuredockerazure-devops

解决方案


推荐阅读