If COPY <src> is not in the current directory,docker will show that it cannot find <src>

If COPY is not in the current directory,docker will show that it cannot find .

cat Dockerfile 
FROM nginx:latest
COPY /etc/nginx/nginx.conf.bak /etc/nginx/nginx.conf



docker build .
Sending build context to Docker daemon  16.38kB
Step 1/2 : FROM nginx:latest
 ---> ed21b7a8aee9
Step 2/2 : COPY /etc/nginx/nginx.conf.bak /etc/nginx/nginx.conf
COPY failed: stat /var/lib/docker/tmp/docker-builder665445903/etc/nginx/nginx.conf.bak: no such file or directory

Why does docker look for the /var/lib/docker directory?

If the file is in the current directory, docker build is working.

cat Dockerfile 
FROM nginx:latest
COPY /etc/nginx/nginx.conf /etc/nginx/nginx.conf


docker build .
Sending build context to Docker daemon  16.38kB
Step 1/2 : FROM nginx:latest
 ---> ed21b7a8aee9
Step 2/2 : COPY nginx.conf.bak /etc/nginx/nginx.conf
 ---> Using cache
 ---> b642c4e0a25f
Successfully built b642c4e0a25f

Hello wajika,

Firstly , you have to checked your .dockerignore file. Maybe your file patterns are excluded from being copying to the image.
Secondly, you need to be aware of the build context. Your file has to be in your build context.

you cannot COPY ../something /something , because the first step of a docker build is to send the context directory (and subdirectories) to the docker daemon.

Best Regards,
Fouscou B.

Thank you for your reply.
There is no dockerignore file in my directory.
Do you mean that ‘COPY ’ can only use the resources of the current directory?