Docker won't copy files from the container to the host's /tmp folder

Viewed 489

I am trying to copy a file from a linux container to a linux host using docker cp. I want to copy this file to the /tmp folder on the host machine.

The problem is simple: I can copy to other places, such as my home folder. For example, this works: docker cp my_container:/certificate.cer /home/adam/Documents/certificate.cer

But this does not work: docker cp my_container:/certificate.cer /tmp/certificate.cer.

However, the command completes with a zero exit code as if the operation was successful. I get no error feedback, but the file definitely isn't there.

Am I missing something, or is this a bug with the Docker CLI?

edit: From further testing I have noticed that creating a new directory in /tmp, (i.e. mkdir /tmp/test) Then trying to copy the file into that subfolder, fails with an error: stat /tmp/test/: not a directory. This seems to indicate that perhaps docker is looking at a different folder? I am not sure where it could be looking though.

Thanks

1 Answers

I believe I have found the answer to this:

Docker was installed as an Ubuntu Snap, which as I understand, is sandboxed. Running sudo ls /tmp/snap.docker/tmp showed me all the files I was missing.

So, it seems the snap version of docker works a little differently than expected. Uninstalling it and reinstalling from apt fixed the problem. :)

Related