Can't copy file from docker to host

Hello Community,

I have a weird problem.

It try to copy a file from a container to the host. but the host can’t find the file:

docker cp 6a1ff0d7bec2:/var/file.txt /
Error response from daemon: Could not find the file /var/file.txt in container

The file is on the right path

The error message says otherwise.

How does the output for docker exec -ti 6a1ff0d7bec2 stat /var/file.txt look like?

Thank you Meyay for your help,

here is the output, files seems not found:
stat: cannot statx ‘/var/file.txt’: No such file or directory

here is the file inside docker container:

root@d1333b36fcef:/var# ls -la
total 2448
drwxr-xr-x. 1 root root       78 Nov 20 08:16 .
-rw-r--r--. 1 root root        4 Nov 20 08:16 file.txt
-rw-r--r--. 1 root root  2497199 Nov 17 09:33 medkeydb.dump

Are you using Docker Desktop? I think I saw this issue only with Docker Desktop when the file on the host had wrong permissions and the in the VM the file was listed but somehow the VM didn’t have right to actually access it. I don’t remember the details.

In this case it is not a bind mount, but copy so it is not the same issue.

And the ls command shows a dot character in the list of permissions which shouldn’t be there normally.

I updated your post to use a code block. So we can see it better. Please follow this guide to share codes, logs or terminal outputs.

Can you copy the file anywhere else in the container?