I have a github actions workflow to build a docker image:
name: Backend-Demo Docker Image CI on: push: branches: [ master ] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Login to Azure Container Registry run: echo ${{ secrets.REGISTRY_PASSWORD }} | docker login ${{ secrets.LOGIN_SERVER_URL }} -u ${{ secrets.REGISTRY_USERNAME }} --password-stdin - name: Get the version id: vars run: echo ::set-output name=tag::$(echo ${GITHUB_REF:10}) - name: Build the tagged Docker image run: docker build . --file backend/Dockerfile --tag backend-demo/spring-boot:v1.0 The Dockerfile is:
FROM openjdk:14-alpine MAINTAINER example.com RUN mkdir -p /opt/demo-0.0.1/lib # Setting application source code working directory WORKDIR /opt/demo-0.0.1/ COPY target/demo-0.0.1-SNAPSHOT.jar /opt/demo-0.0.1/lib/demo-0.0.1-SNAPSHOT.jar # ADD target/demo-0.0.1-SNAPSHOT.jar /opt/demo-0.0.1/lib/ RUN sh -c 'touch demo-0.0.1-SNAPSHOT.jar' ENTRYPOINT ["java"] CMD ["-jar", "/opt/demo-0.0.1/lib/demo-0.0.1-SNAPSHOT.jar"] But when I execute this workflow I got this error at the COPY instruction:
Step 5/8 : COPY target/demo-0.0.1-SNAPSHOT.jar /opt/demo-0.0.1/lib/demo-0.0.1-SNAPSHOT.jar COPY failed: stat /var/lib/docker/tmp/docker-builder851513197/target/demo-0.0.1-SNAPSHOT.jar: no such file or directory ##[error]Process completed with exit code 1. I have been checking and it looks a typical error when the file we have the Dockerfile in a different directory like my instruction:
docker build . --file backend/Dockerfile --tag backend-demo/spring-boot:v1.0
I also don't have .dockerignore file and my Dockerfile is called Dockerfile precisely.
The target/demo-0.0.1-SNAPSHOT.jar file I am trying to copy is present in my github repository Not sure what could be happening with the context, but probably this answer could be a good hint?
Dockerfilein same level astarget/directory in your file tree? you can also try with relative path likeCOPY ./target/demo-0.1.1-SNAPSHOT.jar ...Dockerfileis at the same level astargetdirectory. I also tried with relative PATH atCOPYwithout success.RUN ls -laboveCOPYinstruction to see the contents of directory inside image.