docker COPY failed: no such file or directory - docker

I am trying to copy my project into app folder.
Dockerfile
FROM ubuntu:18.04
RUN mkdir /app
ARG input_project_path
COPY $input_project_path /app
When I run the docker build command it returns the following error and I am running the docker build command in the same directory as my Dockerfile.
ubuntu:~/$ sudo docker build --build-arg input_project_path=/home/ubuntu/web-app/ -t test .
COPY $input_project_path /app
COPY failed: stat /var/lib/docker/tmp/docker-builder055576899/home/ubuntu/web-app/: no such file or directory

You should put all the files/directories that you want to use in COPY in the same directory where your Dockerfile is present.

Try this:
COPY ${input_project_path} /app

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.

dockerfile COPY does not copy all the files

I do
git clone https://github.com/openzipkin/zipkin.git
cd zipkin
The create a Dockerfile as below
FROM openjdk
RUN mkdir app
WORKDIR /app
COPY ./ .
ENTRYPOINT ["sleep", "1000000"]
then
docker build -t abc .
docker run abc
I then run docker exec -it CONTAINER_ID bash
pwd returns /app which is expected
but I ls and see that the files are not copied
only the directories and the xml file is copied into the /app directory
What is the reason? how to fix it?
Also I tried
FROM openjdk
RUN mkdir app
WORKDIR /app
COPY . /app
ENTRYPOINT ["sleep", "1000000"]
That repository contains a .dockerignore file which excludes everything except a set of things it selects.
That repository's docker directory also contains several build scripts for official images and you may find it easier to start your custom image FROM openzipkin/zipkin rather than trying to reinvent it.

docker multiple stages - docker gradle build success but docker openjdk failed to build: COPY failed: no source files were specified

i am trying to build jar files in docker gradle, then docker openjdk copy the jar files and run it.
but hitting error
Step 10/14 : COPY --from=builder /test-command/build/libs/*.jar /app/test-command.jar
ERROR: Service 'test-command' failed to build: COPY failed: no source files were specified
docker file
FROM gradle:5.6.3-jdk8 as builder
COPY --chown=gradle:gradle . /test-command
ADD --chown=gradle . /app
WORKDIR /app
RUN gradle build
FROM ubuntu
FROM openjdk:8-alpine
WORKDIR /app
VOLUME ["/app"]
COPY --from=builder /test-command/build/libs/*.jar /app/test-command.jar
COPY --from=builder /test-command/docker/startup.sh /app/startup.sh
#RUN sh -c 'touch /app/test-command.jar'
RUN chmod +x /app/startup.sh
RUN chmod +x /app/test-command.jar
ENTRYPOINT ["/bin/sh", "/app/startup.sh"]
when the docker gradle building files, i can view them by using below docker command, and i saw the path, jar files in the container.
but once build is completed, then i did not see the container anymore.
could it be the reason why docker oepnjdk cannot find the files / source path??
docker exec -it name-of-container bash

COPY command failing when running DOCKER BUILD

I'm trying to create a Docker image but it's not working. I'm trying to run this Docker command from the CLI and I'm getting the following error:
(from the <repo root>/src/Services/Accounts/Accounts.Api)
> docker build .
Error message:
Step 7/18 : COPY ["src/Services/Accounts/Accounts.Api/Accounts.Api.csproj", "src/Services/Accounts/Accounts.Api/"]
COPY failed: stat /var/lib/docker/tmp/docker-builder937056687/src/Services/Accounts/Accounts.Api/Accounts.Api.csproj: no such file or directory
and here's my Dockerfile
FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 80
FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src
RUN ls -al
COPY ["src/Services/Accounts/Accounts.Api/Accounts.Api.csproj", "src/Services/Accounts/Accounts.Api/"]
COPY ["src/Services/Accounts/Accounts.Api/NuGet.config", "src/Services/Accounts/Accounts.Api/"]
RUN dotnet restore "src/Services/Accounts/Accounts.Api/Accounts.Api.csproj"
COPY . .
WORKDIR "/src/src/Services/Accounts/Accounts.Api"
RUN dotnet build "Accounts.Api.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "Accounts.Api.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "Hornet.Accounts.Api.dll"]
I've also tried running this from the repo root directory:
> docker build .\src\Services\Accounts\Accounts.Api
Why is it trying to find my files in some /var/lib/docker/tmp/blah folder?
Further info:
Windows 10 OS
Docker CE with Linux Containers
VSCode
I think we can solve this by clarifying how to use the build context and how to specify the location of the Dockerfile.
The Docker build command usage looks like this:
docker build [OPTIONS] PATH
Your build context is the location that you define with PATH, Docker can use the files in the build context for the build. (You cannot use files outside the build context for the build.)
In the Dockerfile in your COPY statements you are specifying the source files' location relative to the root of your repo. This implies that
You should run your build command from the <root of your repo> with PATH . like this:
docker build .
You have not specified the path of your Dockerfile in the question, but it seems to me that it's in a subfolder of your repo. To make your build work issue the docker build command from the <root of your repo> like this:
docker build -f <path to Dockerfile> .
Your Dockerfile must be in the build context.
I think getting the build context and the location of the Dockerfile right will fix your build.
Also remember to use the -t flag to tag your image.
Why is it trying to find my files in some /var/lib/docker/tmp/blah folder?
As you probably know, Docker uses a Linux VM under the hood in the Docker for Windows app to develop Linux based containers. This location simply refers to the location in the VM.

will the commands in Dockerfile run as follows?

docker build Dockerfile .//running it correctly.
1.) I have mentioned in the comments each command will execute as written, Is that correct working of this Dockerfile?
2.)These commands will be used to make the image when I ran docker build, so
[ec2-user#ip-xx-xx-xx-xx ~]$cd /project/p1
[ec2-user#ip-xx-xx-xx-xx p1]$ls
Dockerfile a b c d
My Dockerfile consists of following commands.
Dockerfile
node 8.1.0 //puls the image from hub
RUN mkdir -p /etc/x/y //make directory in the host at path /etc/x/y
RUN mkdir /app //make directory in the host at path /app
COPY . /app //copy all the files that is
WORKDIR /app //cd /app; now the working directory will be /app for next commands i.e npm install.
RUN npm install
EXPOSE 3000 //what this will do?
Question 1: how to run docker build?
docker build Dockerfile . # am I running it correctly.
No, you run it with docker build . and docker will automatically look for the Dockerfile in the current directory. Or you use docker build -f Path_to_the_docker_file/DockerFile where you clearly specify the path to the DockerFile.
Question 2: Fixing errors and clarifying commands
There are few mistakes in the Dockerfile, check the edited comments:
# pulls the image from dockerhub : YES
# Needs to be preceeded with FROM
FROM node 8.1.0
# all directories are made inside the docker image
# make directory in the image at path /etc/x/y : YES
RUN mkdir -p /etc/x/y
# make directory in the image at path /app : YES
RUN mkdir /app
COPY . /app # copy all the files that is : YES
WORKDIR /app # cd /app; now the working directory will be /app for next commands i.e npm install. : YES
RUN npm install
EXPOSE 3000 # what this will do? => tells all docker instances of this image to listen on port 3000.

Resources