Docker build gives error when run with codepipeline aws - docker

I'm getting following error when I run Dockerfile with AWS CodePipeline
Step 2/4 : COPY src /app
COPY failed: file not found in build context or excluded by .dockerignore: stat src: file does not exist
This is the command used in buildspec.yml
docker build --tag $REPOSITORY_URI:$TAG -f app/Dockerfile .
folder structure is:
Microservice1/
|-app/
|- src/
|- Dockerfile
|-buildspec.yml

You are executing command at $Microservice1 directory.
Dot (.) at the end of command tells to use build context as current directory.
Docker build context can see only app/src , only src is not visible.
Alternatively, execute command from $Microservice1/app directory. You may have to change Dockerfile a bit.

Related

Copy a file from local filesystem to Docker Container?

I have a dockerfile
FROM myregistry.de/public/12/s11
LABEL maintainer="Me"
COPY ./somefile.txt /opt
CMD /bin/sh
the file I want to copy to Docker Container is in the same folder as the Dockerfile
But when I do docker build -t 'name:tag4' .
I get the error message :
COPY failed: file not found in build context or excluded by .dockerignore: stat somefile.txt: **file does not exist**
So why is this simple copy not working ?
Please check what you get in build context directory by creating another Dockerfile with the following content:
FROM myregistry.de/public/12/s11
RUN mkdir /tmp/build
COPY . /tmp/build
CMD /bin/sh
Then build and run the container and check /tmp/build folder contents.

Windows DockerFile COPY folder

I Have following structure in my project
I'm trying to run
following in cmd
docker build -t counter-bal-image '.\docker.'
My docker file has following line
COPY cicd/scripts/* /App/scripts/
When i run i get COPY failed: no source files were specified
How to copy relative folders?
If you build in ./docker then that's where everything must live. Instead specify the path to the Dockerfile but build in the current directory:
docker build -f docker/Dockerfile -t counter-bal-image .
Since you're building in . then ./cicd becomes accessible.

COPY failed: stat /var/lib/docker/tmp/docker-xxx : no such file or directory

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?
When you run
docker build . --file backend/Dockerfile ...
The path argument . becomes the context directory. (Docker actually sends itself a copy of this directory tree, which is where the /var/lib/docker/tmp/... path comes from.) The source arguments of COPY and ADD instructions are relative to the context directory, not relative to the Dockerfile.
If your source tree looks like
.
+-- backend
| \-- Dockerfile
\-- target
\-- demo-0.0.1-SNAPSHOT.jar
that matches the Dockerfile you show. But if instead you have
.
+-- backend
+-- Dockerfile
\-- target
\-- demo-0.0.1-SNAPSHOT.jar
you'll get the error you see.
If you don't need to refer to anything outside of the context directory, you can just change what directory you're passing to docker build
COPY target/demo-0.0.1-SNAPSHOT.jar /opt/demo-0.0.1/lib/demo-0.0.1-SNAPSHOT.jar
docker build backend ...
Or, if you do have other content you need to copy in, you need to change the COPY paths to be relative to the topmost directory.
COPY backend/target/demo-0.0.1-SNAPSHOT.jar /opt/demo-0.0.1/lib/demo-0.0.1-SNAPSHOT.jar
COPY common/config/demo.yml /opt/demo-0.0.1/etc/demo.yml
docker build . -f backend/Dockerfile ...
WORKDIR just tells you from where the other commands will be executed.An important point is WORKDIR works w.r.t docker directory,not to local/git directory.As per your example, WORDIR does not take context to /opt/demo-0.0.1/ , but just creates an empty directory as /opt/demo-0.0.1/ inside the docker. In order to make dockerfile work, you should give full path in COPY command as COPY /opt/demo-0.0.1/target/demo-0.0.1-SNAPSHOT.jar /opt/demo-0.0.1/lib/demo-0.0.1-SNAPSHOT.jar.Make sure Dockerfile is at the same level as /opt directory.

Not able to create docker image of .net core web API - COPY failed: stat /var/lib/docker/tmp/../netcoreapp2.1/publish

I'm trying to build an image of a .netcore v2.2 WebAPI app from docker file. But I'm getting a "no such file or directory" error while I try to build the image using following command:
docker build -t helloworld .
I have both microsoft/dotnet "latest" and "2.2-aspnetcore-runtime" base images installed in my machine.
Here's my docker file
FROM microsoft/dotnet
RUN mkdir /app
COPY ./bin/Release/netcoreapp2.2 /app
WORKDIR /app
ENTRYPOINT ["dotnet", "/app/HelloWorld.dll"]
# ASP.NET Core: Kestrel should listen on all IPs
ENV ASPNETCORE_URLS="http://0.0.0.0:5000"
Here's the folder structure of my solution (I tried the command inside the src):
Here's the output directory
Here's the full error details from the docker:
COPY failed: stat /var/lib/docker/tmp/docker-builder896068669/bin/Release/netcoreapp2.2: no such file or directory
you may change ./bin/Release/netcoreapp2.2 to ./bin/release/netcoreapp2.2
folder names are case sensitive
It seems the file ./bin/Release/netcoreapp2.2/publish does not exists on the machine on which you are running docker build
When you run docker build -t helloworld . it will copy all the file in . (i.e. the current directory from which you run the command) to the build context which will then be used when running COPY instructions, so you need to make sure you are running your command from the proper directory where files will be available to COPY
You can also run the same command from another directory by specifying the path to be used as build context such as docker build -t helloworld /path/to/my/dir

Ubuntu Docker - php composer build from the official Dockerfile fails, COPY failed Step 9/12 stat no such file or directory

I want to build a docker image of a composer from this page composer:latest and taking exactly this Dockerfile
but when I do this in console:
$ wget -O Dockerfile https://raw.githubusercontent.com/composer/docker/edf4f0abf50da5d967408849434b9053a195b65f/1.7/Dockerfile
$ docker build -t mycomposer:latest .
i got this build error:
Step 9/12 : COPY docker-entrypoint.sh /docker-entrypoint.sh COPY
failed: stat
/var/lib/docker/tmp/docker-builder787686173/docker-entrypoint.sh: no
such file or directory
How come I have any error building from official Dockerfile?
This way works:
$ docker pull composer:latest
but I need to build an image basing on a local Dockerfile instead of just pulling it.
The command
COPY docker-entrypoint.sh /docker-entrypoint.sh
in the Dockerfile tries to copy the file docker-entrypoint.sh from your current directory.
However you have only downloaded the Dockerfile.
If you visit the actual directory on the repository you will notice another file entitled
docker-entrypoint.sh. If you download this file too and place it in the same directory
as the Dockerfile the image will be built without errors.

Resources