Search code examples
dockerdocker-cp

Can't use docker cp to copy file from /tmp


When using docker cp to move files from my local machine /tmp/data.txt to the container, it fails with the error:

lstat /tmp/data.txt: no such file or directory

The file exists and I can run stat /tmp/data.txt and cat /tmp/data.txt without any issues.

Even if I create another file in /tmp like data2.txt I get the exact same error.

But if I create a file outside /tmp like in ~/documents and copy it with docker cp it works fine.

I checked out the documentation for docker cp and it mentions:

It is not possible to copy certain system files such as resources under /proc, /sys, /dev, tmpfs, and mounts created by the user in the container

but doesn't mention /tmp as such a directory.

I'm running on Debian 10, but a friend of mine who is on Ubuntu 20.04 can do it just fine.

We're both using the same version of docker (19.03.11).

What could be the cause?


Solution

  • I figured out the solution.

    I had install docker as a snap. I uninstalled it (sudo snap remove docker) and installed it using the official Docker guidelines for installing on Debian.

    After this, it worked just fine.

    I think it might've been due to snap packages having limited access to system resources - but I don't know for sure.