我正在学习 Docker,我非常喜欢它。
但是,我不明白,为什么docker需要root权限来制作容器、读取日志等。
我读过一些像这样的文章
https://docs.docker.com/articles/security/
但我所看到的只是“docker需要根权限,因为它可以访问根文件夹”。好吧,我不介意以非 root 用户身份运行 docker,并让他们只能访问外部系统中非 root 用户拥有的文件夹。
为什么这是一个问题?
我开始使用 postgres docker 容器
sudo docker run --name some-postgres -d postgres
然后尝试使用连接到它
sudo docker run -it --rm --link some-postgres:postgres postgres psql -h postgres
这给出了错误 psql: FATAL: role "root" does not exist
这些命令与docker hub 页面上列出的命令完全相同仅以 root 身份运行,不以-e POSTGRES_PASSWORD=mysecretpassword
我在这里做错了吗?什么可能导致这种情况?
我有以下 Dockerfile 用于创建一个包含 powerdns 递归的容器:
FROM debian:stretch-slim
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && \
apt-get install --no-install-recommends -y \
pdns-recursor && \
rm -rf /var/lib/apt/lists/* && \
apt-get clean
COPY ./configuration/recursor.conf /etc/powerdns/recursor.conf
RUN chown -R :pdns /etc/powerdns/ && \
chmod 0750 /etc/powerdns/ && \
chmod 0640 /etc/powerdns/recursor.conf
EXPOSE 8699
ENTRYPOINT ["/usr/sbin/pdns_recursor", "--daemon=no"]
Run Code Online (Sandbox Code Playgroud)
我的recursor.conf看起来像这样:
config-dir=/etc/powerdns
forward-zones=resolver1.opendns.com=208.67.222.222
hint-file=/usr/share/dns/root.hints
local-address=0.0.0.0
local-port=8699
quiet=yes
security-poll-suffix=
setgid=pdns
setuid=pdns
Run Code Online (Sandbox Code Playgroud)
虚拟机管理程序上禁用了 IPv6。
问题是 docker 无法使用docker stop recursor. 一段时间后,OOMKiller 使用以下信息终止程序:
Exited (137) 2 seconds …Run Code Online (Sandbox Code Playgroud) 给定 podman 安装在 linux 系统和一个名为 baz.service 的 systemd 单元上:
# /etc/systemd/system/baz.service
[Service]
ExecStart=/usr/bin/podman run --rm --tty --name baz alpine sh -c 'while true; do date; sleep 1; done'
ExecStop=/usr/bin/podman stop baz
Run Code Online (Sandbox Code Playgroud)
然后 baz.service 启动:
# systemctl daemon-reload
# systemctl start baz.service
Run Code Online (Sandbox Code Playgroud)
然后当我检查单元的状态时,我在 /system.slice/baz.service cgroup中看不到shorsleep进程
# systemctl status baz
? baz.service
Loaded: loaded (/etc/systemd/system/baz.service; static; vendor preset: enabl
Active: active (running) since Sat 2019-08-10 05:50:18 UTC; 14s ago
Main PID: 16910 (podman)
Tasks: 9
Memory: 7.3M
CPU: …Run Code Online (Sandbox Code Playgroud) 我已成功将 Debian buster 升级到最新版本(Bullseye),之后,每当我想要重新启动或关闭它时,都需要几分钟才能完成,同时等待某些进程完成并显示以下消息:
watchdog: watchdog0: watchdog did not stop!
systemd-shutdown[1]: Syncing filesystem and block devices.
systemd-shutdown[1]: Sending SIGTERM to remaining process...
systemd-journald[372]: Received SIGTERM from PID 1 (systemd-shutdown).
systemd-shutdown[1]: waiting for process: containerd-shim.
Run Code Online (Sandbox Code Playgroud)
我的系统上安装了 docker,这似乎是问题的原因。
$ ps aux | grep containerd-shim
root 3420 0.0 0.1 1451744 21876 ? Sl 11:07 0:00 /usr/bin/containerd-shim-runc-v2 -namespace moby -id 0dd6b89a62d...66cc5c0a44b6f01d77c -address /run/containerd/containerd.sock
$ dpkg -S /usr/bin/containerd-shim-runc-v2
containerd: /usr/bin/containerd-shim-runc-v2
$ aptitude why containerd
i docker.io Depends containerd
Run Code Online (Sandbox Code Playgroud)
我尝试在重新启动系统之前停止泊坞窗的服务/套接字。没有改变。
知道如何解决这个问题吗?
$ docker version
Client:
Version: …Run Code Online (Sandbox Code Playgroud) 码头工人的新手。
从mint 17.
当我跑步时, docker run hello-world我收到:
FATA[0000] Error response from daemon: Cannot start container a6bcc1ede2c38cb6b020cf5ab35ebd51b64535af57fa44f5966c37bdf89c8781: [8] System error: mountpoint for devices not found
Run Code Online (Sandbox Code Playgroud)
当我查看服务日志 ( /var/log/upstart/docker.log) 时,我看到:
ERRO[0617] Couldn't run auplink before unmount: exec: "auplink": executable file not found in $PATH
ERRO[0617] Couldn't run auplink before unmount: exec: "auplink": executable file not found in $PATH
Run Code Online (Sandbox Code Playgroud)
: 码头工人版本
Client version: 1.6.2
Client API version: 1.18
Go version (client): go1.2.1
Git commit (client): 7c8fca2
OS/Arch (client): linux/amd64 …Run Code Online (Sandbox Code Playgroud) 我从下面的 Dockerfile 构建容器:
FROM ubuntu:14.04
...
RUN apt-get update && apt-get install -y vim
#RUN ssh-keygen -f /root/.ssh/id_rsa -N strongpass123$%^
RUN ssh-keygen -f /root/.ssh/id_rsa
...
Run Code Online (Sandbox Code Playgroud)
我很少这样做,但是在使用之前ssh-keygen和之后有很多命令。
我知道我可以从脚本开始docker exec -it thirsty_darwin sh script.sh,然后标记图像,然后使用容器(图像)链接,但这并不是我想要的清晰解决方案。
甚至最坏的情况是ssh-add ~/.ssh/id_rsa当我必须使用 expect 工具时。Expect 工具对我的密码进行了硬编码。我不想做这件事。
我正在尝试git clone myuser@server:repo.git从 docker 容器中运行 a 。在容器内(由于政策),我与 docker 主机系统(非 root)上的用户相同,并且我的家已安装。
可悲的是,当从或尝试通过 ssh 克隆时,server我收到如下错误消息:
No user exists for uid 1337
Run Code Online (Sandbox Code Playgroud)
要重现该问题,您可以运行以下 docker 容器:
docker run --rm -it -v /home/$USER:/home/$USER -e HOME=/home/$USER -w /home/$USER -u $UID:100 --cap-drop=ALL kiesel/debian-ssh-client
Run Code Online (Sandbox Code Playgroud)
并在容器内执行以下任一命令:
git clone myuser@server:repo.git
ssh -vT myuser@server
Run Code Online (Sandbox Code Playgroud)
/etc/passwd为我的 uid添加一行伪造似乎可以解决问题(例如getent passwd $USER > /tmp/mypasswd,然后将 a 添加-v /tmp/mypasswd:/etc/passwd:ro到docker runcmd)。
可悲的是,这需要遮蔽/修改容器的/etc/passwd,我可以想象这会在某些时候导致麻烦。
/etc/passwd?是否可以在不使用 systemd (systemctl) 的情况下在 CentOS/Fedora 发行版中启动服务和启动后?如果是,如何?
Systemd 在非特权 docker 容器中不起作用;因此,此时我只能在特权容器中启动服务,而我不想这样做。
谢谢。
我正在尝试将我的 Linux 机器设置为运行多个来宾操作系统,其中一个是 Windows VM,另一个是 Linux 容器。这里的目标是防止我弄乱主机系统,同时可以自由地操作基本操作系统并使用主机硬件。最终,除了在容器中运行我的桌面之外,我还希望运行图形加速模拟等。由于 Docker 内置了非常棒的类似 git 的容器版本控制,因此使用它似乎是一个好主意。也许 libvirt 和 LXC 一样好,但是 docker 的特权模式使得不必为容器配置设备变得更容易。
我已经做了一些研究并已经提出了一些答案,但是我无法将它们放在一起。
从 LXC 运行 X帮助我了解如何使用(即)配置容器:
lxc.cgroup.devices.allow = c 226:0 rwm
并使用
mknod -m 666 dri/card0 c 226 0
在容器内连接到主机设备。
从cuda - 使用来自 docker 容器的 GPU,我看到我可以通过 LXC 后端获得相同的设置以在 Docker 中工作。
在我看来,如果 docker 容器在特权模式下运行,那么它可以正常访问 GPU,而无需进行此额外配置。所以,我启动了一个基本系统,安装了图形驱动程序、xorg-server、xorg-xinit 和一个窗口管理器来测试它。
# startx
Cannot run from a console (or some message like that)
Run Code Online (Sandbox Code Playgroud)
好吧,我以为我在 tty2 上。
# tty
/dev/console
Run Code Online (Sandbox Code Playgroud)
那不是我所期望的。
# chvt 2 …Run Code Online (Sandbox Code Playgroud) docker ×10
systemd ×3
debian ×2
fedora ×2
ssh ×2
centos ×1
cgroups ×1
containers ×1
desktop ×1
expect ×1
kill ×1
libcontainer ×1
linux-mint ×1
lxc ×1
passwd ×1
postgresql ×1
process ×1
reboot ×1
shutdown ×1
ssh-keygen ×1