简体   繁体   English

如何在Google Cloud上Compute Engine VM上的容器优化操作系统中的docker中运行docker?

[英]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.

相关问题 Google GCP 容器优化操作系统 - 在 docker-compose 构建期间没有剩余空间 - Google GCP container-optimized OS - no space left during docker-compose build Boot2Docker到Google Compute Engine VM:保存Docker容器 - Boot2Docker to Google Compute Engine VM: saving Docker container 如何停止和重新启动运行Docker容器的Compute Engine VM - How to stop and restart a Compute Engine VM that runs a Docker container 如何在 Container-Optimized OS 中设置容器 ulimits - how to set container ulimits in Container-Optimized OS 如何将 docker 容器目录复制到 Google Compute Engine 实例 - How to copy docker container directories to Google Compute Engine instance Cloud Run Docker 容器 - 如何访问 VM 上的数据库? - Cloud Run Docker container - How to access DB on VM? 关闭 Google Compute Engine VM 时优雅地停止 docker 容器 - Gracefully stop docker container when shutting down Google Compute Engine VM 如何在 Google Compute Engine 上运行 Docker? - How do I run Docker on Google Compute Engine? Cloud Logging 不适用于运行容器的容器优化操作系统 - Cloud Logging doesn't work on a Container-optimized OS running a container 从计算引擎中的 docker 容器连接到 Cloud SQL - Connecting to Cloud SQL from docker container in compute engine
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM