我正在关注文章中链接的以下 youtube 视频,该视频允许 docker 容器在主机上获得 root 访问权限。
有几个步骤不清楚,有人可以解释一下它们是如何进一步工作的吗?
https://www.lvh.io/posts/dont-expose-the-docker-socket-not-even-to-a-container.html
Step 1> Bind mount /var/run/docker.sock from host to container
Step 2> Install docker in container <<< at this stage I see that docker ps
-a shows all the containers which are present on the host.
**QUESTION:** How can the container see the containers present on the host? Is it because dockerd on the new container is using /var/run/docker.sock on the host? netstat/ss in the new container doesn't show anything..
Step 3> Run another container from the 1st container. Pass the following parameters to it:
docker run -dit -v /:/host ubuntu
Intention of this is to mount / from host filesystem to /host in the 2nd container being created
**QUESTION:** How does the 1st container have access to / (being filesystem of the host?)
Run Code Online (Sandbox Code Playgroud)
谢谢。
Dockerservice在主机上作为 a 运行。这service通过套接字与客户端通信,默认情况下,该套接字是 unix 套接字:unix:/var/run/docker.sock。
当您与任何容器共享此套接字时,该容器将获得对 docker 守护程序的完全访问权限。从那里,容器可以启动其他容器,删除容器/卷/等,甚至可以随意将卷从主机映射到新容器,例如,如您的问题中所述-v /:/host。这样做将使容器 root 访问/host/.
简而言之:你应该小心地与任何你不信任的容器共享这个宝贵的套接字。在某些情况下,共享套接字是有意义的(例如portainer:用作 docker 管理 GUI 的容器)。
| 归档时间: |
|
| 查看次数: |
1672 次 |
| 最近记录: |