docker 容器中的 mktemp 失败,但 touch 可以工作

docker 容器中的 mktemp 失败,但 touch 可以工作

我位于一个 docker 容器中,其中映射了一个 NFS 卷。在卷内的目录中,我可以通过touch或其他方法创建文件,但不能使用mktemp

$ ls -ld /home/share/scripts/converth264queue/
drwxrwxr-x 1 abc abc 964 Oct 22 08:04 /home/share/scripts/converth264queue/
$ touch /home/share/scripts/converth264queue/test2
$ ls -l /home/share/scripts/converth264queue/test2
-rw-r--r-- 1 abc abc 10 Oct 22 08:04 /home/share/scripts/converth264queue/test2
$ cat > /home/share/scripts/converth264queue/test3
test
etst

$ mktemp -p /home/share/scripts/converth264queue file.XXXXXXXX
mktemp: failed to create file via template ‘/home/share/scripts/converth264queue/file.XXXXXXXX’: Permission denied
$ mktemp -p /home/share/scripts/converth264queue
mktemp: failed to create file via template ‘/home/share/scripts/converth264queue/tmp.XXXXXXXXXX’: Permission denied
$ id
uid=1000(abc) gid=100(abc) groups=100(abc),1000(users)
$ ls -lnd /home/share/scripts/converth264queue/
drwxrwxr-x 1 1000 100 964 Oct 22 08:04 /home/share/scripts/converth264queue/

知道为什么会发生这种情况吗?

注意,docker 中的 mktemp 由 coreutils 提供,因此没有 setuid:

$ ls -ld $(which mktemp)
lrwxrwxrwx 1 root root 20 Oct 20 09:09 /bin/mktemp -> ../usr/bin/coreutils
$ ls -ld /usr/bin/coreutils
-rwxr-xr-x 1 root root 1065928 May  1 21:44 /usr/bin/coreutils

相关内容