COPY failed: file not found in build context - docker

I am having the following issue when I run docker build -> DOCKERFILE
COPY failed: file not found in build context or excluded by .dockerignore: stat requirements_webserver.txt: file does not exist
Relevant code from DOCKERFILE:
COPY requirements_webserver.txt /requirements.txt
Here is the directory:
It wont find either the requirements_webserver.txt or the requirements.txt file.
thanks.

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.

Docker build gives error when run with codepipeline aws

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.

Docker - COPY failed: file not found in build context or excluded by .dockerignore: stat test.com: file does not exist [duplicate]

This question already has answers here:
Docker - COPY file from different working directory to another is not working
(2 answers)
Closed last year.
I have the following dockerfile:
FROM nginx:1.21.3-alpine
COPY ./conf.d /etc/nginx/conf.d
RUN apk update && apk add git
RUN git clone https://username:token#github.com/username/test.com.git
RUN echo $(ls -l)
COPY ./test.com /usr/share/nginx/html
I am downloading the contents of the test repository. It contains the index.html file. Next, I try to copy the contents of the repository folder to the /usr/share/nginx/html folder, but I get the error:
COPY failed: file not found in build context or excluded by .dockerignore: stat test.com: file does not exist
I added the execution of the command ls -l and the list contains a test.com folder with the index.html file, but then why does the error occur?
COPY copies from the host machine.
Here you want to copy from inside the container. You do that with RUN cp instead. Change your statement to
RUN cp ./test.com /usr/share/nginx/html

Docker copy file - no such file or directory

I cannot copy file to container from my host.
this is my docker file :
COPY /vagrant/somefile.json somefile.json
This is the full path to the file :
/vagrant/somefile.json
this is the path of the Dockerfile:
/vagrant/static/app/Dockerfile
i get :
---> dba663c523a9
Step 3/20 : COPY /vagrant/somefile.json somefile.json
ERROR: Service 'node' failed to build: COPY failed: stat /var/lib/docker/tmp/docker-builder330278780/vagrant/somfile.json: no such file or directory
To quote the COPY documentation:
The path must be inside the context of the build
In layman's words, any file you want to copy in to the container needs to be in the same directory as the Dockerfile, or some subdirectory of it. If you start by placing somefile.json in /vagrant/static/app/, you should be able to use:
COPY ./somefile.json somefile.json
Generic Format:
copy_command source_file Destination
Please try this!
COPY /vagrant/somefile.json /root/somefile.json
OR
COPY /vagrant/somefile.json /tmp/somefile.json
OR
mkdir ~/new
COPY /vagrant/somefile.json ~/new/somefile.json

docker COPY failed: no such file or directory

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

Resources