[英]How to run docker in docker in Container-optimized OS on Compute Engine VM on Google Cloud?
I have a master container instance (Node.js) that runs some tasks in a temporary worker docker container. 我有一个主容器实例(Node.js),它在一个临时worker Docker容器中运行一些任务。
The base image used is node:8-alpine
and the entrypoint command executes with user node
(non-root user). 使用的基本映像是
node:8-alpine
,而entrypoint命令以用户node
(非root用户)执行。
I tried running my container with the following command: 我尝试使用以下命令运行容器:
docker run \
-v /tmp/box:/tmp/box \
-v /var/run/docker.sock:/var/run/docker.sock \
ifaisalalam/ide-taskmaster
But when the nodejs app tries running a docker container, permission denied error is thrown - the app can't read /var/run/docker.sock
file. 但是,当nodejs应用尝试运行docker容器时,会引发权限被拒绝错误-该应用无法读取
/var/run/docker.sock
文件。
Accessing this container through sh
and running ls -lha /var/run/docker.sh
, I see that the file is owned by root:412
. 通过
sh
访问该容器并运行ls -lha /var/run/docker.sh
,我看到该文件归root:412
。 That's why my node
user can't run docker container. 这就是为什么我的
node
用户无法运行docker容器的原因。
The /var/run/docker.sh
file on host machine is owned by root:docker
, so I guess the 412
inside the container is the docker group ID of the host machine. 主机上的
/var/run/docker.sh
文件由root:docker
拥有,因此我猜容器内的412
是主机的Docker组ID。
I'd be glad if someone could provide me an workaround to run docker from docker container in Container-optimized OS on GCE. 如果有人可以为我提供一种变通办法,以便在GCE上针对容器优化的OS中从docker容器运行docker,我将感到非常高兴。
The source Git repository link of the image I'm trying to run is - https://github.com/ifaisalalam/ide-taskmaster 我要运行的图像的源Git存储库链接是-https: //github.com/ifaisalalam/ide-taskmaster
Adding the following command into my start-up script of the host machine solves the problem: 将以下命令添加到主机的启动脚本中即可解决此问题:
sudo chmod 666 /var/run/docker.sock
I am just not sure if this would be a secure workaround for an app running in production. 我只是不确定对于在生产中运行的应用程序这是否是安全的解决方法。
EDIT: 编辑:
This answer suggests another approach that might also work - https://stackoverflow.com/a/47272481/11826776 这个答案暗示了另一种可能也可行的方法-https: //stackoverflow.com/a/47272481/11826776
Also, you may read this article - https://denibertovic.com/posts/handling-permissions-with-docker-volumes/ 另外,您可以阅读这篇文章-https://denibertovic.com/posts/handling-permissions-with-docker-volumes/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.