Error response from daemon: Could not find the file /report.txt in container
fix8-cli-cp means the path after the colon does not exist inside that container.
docker cp reads that path from the container's root folder. Find the file with
docker exec ... find, then copy it with the right path.
The container itself was found, so the name is right; only the path is wrong. A wrong container name gives a different message:
PS> docker cp fix8-cli-nope:/tmp/report.txt .
Error response from daemon: No such container: fix8-cli-nope
So the wording tells you which half of container:path to check.
The error
PS> docker cp fix8-cli-cp:/report.txt .
Error response from daemon: Could not find the file /report.txt in container fix8-cli-cp
Why it happens
The container wrote its file to /tmp/report.txt, but the command asked for
/report.txt. docker cp reads the container's filesystem
exactly at the path given; it does not search, and it does not know which folder the
application was working in.
A path without a leading slash does not help either: it is read from the container's
root folder, not from its working directory. In a second container started with
-w /tmp, where pwd printed /tmp, the short name
failed and the path from the root worked:
PS> docker cp fix8-cli-cp2:report.txt report2.txt
Error response from daemon: Could not find the file report.txt in container fix8-cli-cp2
PS> docker cp fix8-cli-cp2:tmp/report.txt report2.txt
The fix
PS> docker exec fix8-cli-cp find / -name report.txt
/tmp/report.txt
PS> docker cp fix8-cli-cp:/tmp/report.txt .
PS> type report.txt
report
find run inside the container gives the real path; with that path
docker cp copied the file into the current folder and printed nothing on
success in this run. The test container was still running, which docker
exec needs.
Read the message as two checks. If it says No such container, the part
before the colon is wrong: check it against docker ps -a. If it says
Could not find the file, the container is right and the part after the
colon is wrong. The message repeats the path exactly as Docker received it, so compare
it with what find printed, character by character, before you try again.
In the test the only difference was the missing /tmp folder at the front.
How it was reproduced
Docker Desktop on Windows 11, client and engine 29.9.2, Windows PowerShell 5.1, the
cached alpine:latest image. The container was started with
docker run -d --name fix8-cli-cp alpine sh -c "echo report > /tmp/report.txt;
sleep infinity"; copying /report.txt gave the message above, and
copying /tmp/report.txt worked. The container name is the test's own.
Frequently asked
- How do I find a file's path inside a Docker container?
- Run docker exec <container> find / -name <file>. It prints every matching path, which you can then pass to docker cp.
- Does docker cp need an absolute path inside the container?
- The path is read from the container's root folder, with or without a leading slash. In this test report.txt failed in a container whose working directory was /tmp, while tmp/report.txt and /tmp/report.txt both worked.
- What does Could not find the file in container mean in docker cp?
- The container exists but nothing exists at the path after the colon. Check the path with docker exec and find, then run docker cp again with the right path.
More decoded errors in the Fixes category. If
docker exec fails because the container has stopped, see
container
is not running.