简体   繁体   English

为什么我的 docker 容器不尊重我的权限?

[英]Why isn't my docker container respecting my permissions?

Dockerfile: Dockerfile:

FROM ubuntu:latest

RUN apt install -y bash

CMD []

build and run:构建并运行:

docker build -t test .
docker run -it test bash

minimal reproduction:最小复制:

root@8807902e27b4:/# mkdir parent
root@8807902e27b4:/# cd parent
root@8807902e27b4:/parent# mkdir example
root@8807902e27b4:/parent# chmod 000 example
root@8807902e27b4:/parent# ls -la
total 12
drwxr-xr-x 3 root root 4096 Apr 28 19:33 .
drwxr-xr-x 1 root root 4096 Apr 28 19:32 ..
d--------- 2 root root 4096 Apr 28 19:33 example
root@8807902e27b4:/parent# cd example
root@8807902e27b4:/parent/example# echo "test" > test.txt
root@8807902e27b4:/parent/example# chmod 100 test.txt
root@8807902e27b4:/parent/example# cat test.txt
test
root@8807902e27b4:/parent/example# ls -la
total 12
d--------- 2 root root 4096 Apr 28 19:33 .
drwxr-xr-x 3 root root 4096 Apr 28 19:33 ..
---x------ 1 root root    5 Apr 28 19:33 test.txt

In the above example, the cd example command should fail, and even if it doesn't, running cat test.txt should fail.在上面的示例中, cd example命令应该会失败,即使没有,运行cat test.txt也会失败。 Anyone know what's up?有谁知道怎么回事?

Here are the same (working) commands run in osx:以下是在 osx 中运行的相同(工作)命令:

beaushinkle@Beaus-MBP ~/p/example-docker> mkdir parent
beaushinkle@Beaus-MBP ~/p/example-docker> cd parent
beaushinkle@Beaus-MBP ~/p/e/parent> mkdir example
beaushinkle@Beaus-MBP ~/p/e/parent> chmod 000 example
beaushinkle@Beaus-MBP ~/p/e/parent> cd example
cd: Permission denied: 'example'
beaushinkle@Beaus-MBP ~/p/e/parent [1]> chmod 777 example
beaushinkle@Beaus-MBP ~/p/e/parent> cd example
beaushinkle@Beaus-MBP ~/p/e/p/example> echo "test" > test.txt
beaushinkle@Beaus-MBP ~/p/e/p/example> chmod 100 test.txt
beaushinkle@Beaus-MBP ~/p/e/p/example> cat test.txt
cat: test.txt: Permission denied

If the prompt is anything to go by, we are logged in as root in the minimal reproduction.如果提示是 go 的任何内容,我们在最小复制中以root身份登录。 Thus, we have root privileges and can read and write all files (external link) .因此,我们拥有root 权限,可以读取和写入所有文件(外部链接)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM