
我這裡有一個奇怪的問題,我不明白出了什麼問題。
我在 Linux 機器(Ubuntu 16.04 LTS)上的 docker 容器中運行所有內容:
docker run -ti --rm promregator/promregator:0.2.1 /bin/bash
(註:該圖像可透過 公開取得hub.docker.com
)。命令
docker version
(在主機上)返回
Client:
Version: 1.12.3
API version: 1.24
Go version: go1.6.3
Git commit: 6b644ec
Built: Wed Oct 26 22:01:48 2016
OS/Arch: linux/amd64
Server:
Version: 1.12.3
API version: 1.24
Go version: go1.6.3
Git commit: 6b644ec
Built: Wed Oct 26 22:01:48 2016
OS/Arch: linux/amd64
在容器中,我想建立一個這樣的檔案:
promregator@6a68713fafc9:/$ cd /opt/promregator
promregator@6a68713fafc9:/opt/promregator$ touch test
touch: cannot touch 'test': Permission denied
(promregator 是影像預設運行的使用者)。注意
- 該目錄直接來自映像,未進行磁碟區映射。
此目錄由同一使用者擁有,權限為 0750:
promregator@6a68713fafc9:/opt/promregator$ ls -al total 34348 drwxr-x--- 2 promregator promregator 4096 Apr 1 01:00 . drwxr-xr-x 5 root root 4096 Mar 20 01:01 .. -rw-r----- 1 promregator promregator 35159385 Apr 1 00:59 promregator.jar -rwxrwx--- 1 promregator promregator 642 Apr 1 00:57 promregator.sh
從數字上看,用戶數為 1000
promregator@6a68713fafc9:/opt/promregator$ ls -aln . total 34348 drwxr-x--- 2 1000 1000 4096 Apr 1 01:00 . [...]
另請注意,同樣的操作適用於/home/promregator
:
promregator@6a68713fafc9:/opt/promregator$ cd /home/promregator
promregator@6a68713fafc9:~$ touch test
promregator@6a68713fafc9:~$ ls -al .
total 8
drwx------ 2 promregator promregator 4096 Apr 7 11:45 .
drwxr-xr-x 4 root root 4096 Apr 7 11:45 ..
-rw-r--r-- 1 promregator promregator 0 Apr 7 11:45 test
promregator@6a68713fafc9:~$ ls -aln .
total 8
drwx------ 2 1000 1000 4096 Apr 7 11:45 .
drwxr-xr-x 3 0 0 4096 Apr 7 11:45 ..
-rw-r--r-- 1 1000 1000 0 Apr 7 11:45 test
請注意,如果我使用 root 身分執行容器
docker run -ti --rm -u root promregator/promregator:0.2.1 /bin/bash
我可以在第一個位置建立文件:
root@eb29fa8acb95:/# cd /opt/promregator/
root@eb29fa8acb95:/opt/promregator# touch test
這告訴我用戶有些「奇怪」promregator
。
在不同的主機上(我比較了圖像的 sha1 id),如果容器以docker run -ti --rm promregator/promregator:0.2.1 /bin/bash
.該主機的版本資訊表明
Client:
Version: 17.12.0-ce
API version: 1.35
Go version: go1.9.2
Git commit: c97c6d6
Built: Wed Dec 27 20:11:19 2017
OS/Arch: linux/amd64
Server:
Engine:
Version: 17.12.0-ce
API version: 1.35 (minimum version 1.12)
Go version: go1.9.2
Git commit: c97c6d6
Built: Wed Dec 27 20:09:54 2017
OS/Arch: linux/amd64
Experimental: false
有什麼想法、提示……對我來說,這可能是什麼?
先致謝!
答案1
我今天遇到了同樣的問題。我的解決方案是透過「setenforce 0」關閉selinux。