Docker build failing in Azure Pipelines with COPY command

  azure, azure-devops, docker, dockerfile

I have created a simple Java project that I have containerised with Docker using a Dockerfile. The project builds fine from the command line, though when trying to run it using the default Docker pipeline in Azure DevOps it fails on COPY with the following error:

COPY failed: file not found in build context or excluded by .dockerignore: stat target/classes/dev: file does not exist

This is the contents of my Dockerfile:

FROM openjdk:latest
COPY ./target/classes/com /tmp/com
WORKDIR /tmp
ENTRYPOINT ["java", "com.sample.app.App"]

This is my azure-pipelines.yml

trigger:
- master

resources:
- repo: self

stages:
- stage: Build
  displayName: Build image
  jobs:
  - job: Build
    displayName: Build
    pool:
      vmImage: ubuntu-latest
    steps:
    - task: [email protected]
      displayName: Build an image
      inputs:
        command: build
        dockerfile: '$(Build.SourcesDirectory)/Dockerfile'
        buildContext: '$(Build.Repository.LocalPath)'

I have tried changing the buildContext and the pipeline still fails. Could someone help me with what I am doing wrong?

Source: Docker Questions

LEAVE A COMMENT