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

Viewed 5613

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?

1 Answers

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
Related