无法使用 docker cp 从 /tmp 复制文件
Can't use docker cp to copy file from /tmp
当使用 docker cp
将文件从我的本地计算机 /tmp/data.txt
移动到容器时,它失败并显示错误:
lstat /tmp/data.txt: no such file or directory
文件存在,我可以 运行 stat /tmp/data.txt
和 cat /tmp/data.txt
没有任何问题。
即使我在 /tmp
中创建另一个文件,如 data2.txt
,我也会得到完全相同的错误。
但是如果我像在 ~/documents
中那样在 /tmp
之外创建一个文件并用 docker cp
复制它,它就可以正常工作。
我在 the documentation 中查看了 docker cp
,它提到:
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
但没有提到 /tmp
这样的目录。
我 运行 正在使用 Debian 10,但我的一个朋友在 Ubuntu 20.04 上可以做到。
我们都使用相同版本的 docker
(19.03.11)。
可能是什么原因?
我想出了解决办法。
我很快就安装了 docker
。我卸载它 (sudo snap remove docker
) 并使用官方 Docker guidelines 安装它以便在 Debian 上安装。
在此之后,它工作得很好。
我认为这可能是因为 snap 包对系统资源的访问权限有限 - 但我不确定。
当使用 docker cp
将文件从我的本地计算机 /tmp/data.txt
移动到容器时,它失败并显示错误:
lstat /tmp/data.txt: no such file or directory
文件存在,我可以 运行 stat /tmp/data.txt
和 cat /tmp/data.txt
没有任何问题。
即使我在 /tmp
中创建另一个文件,如 data2.txt
,我也会得到完全相同的错误。
但是如果我像在 ~/documents
中那样在 /tmp
之外创建一个文件并用 docker cp
复制它,它就可以正常工作。
我在 the documentation 中查看了 docker cp
,它提到:
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
但没有提到 /tmp
这样的目录。
我 运行 正在使用 Debian 10,但我的一个朋友在 Ubuntu 20.04 上可以做到。
我们都使用相同版本的 docker
(19.03.11)。
可能是什么原因?
我想出了解决办法。
我很快就安装了 docker
。我卸载它 (sudo snap remove docker
) 并使用官方 Docker guidelines 安装它以便在 Debian 上安装。
在此之后,它工作得很好。
我认为这可能是因为 snap 包对系统资源的访问权限有限 - 但我不确定。