在Docker容器中运行Docker:无法连接到Docker守护程序

编程入门 行业动态 更新时间:2024-10-26 02:34:50
本文介绍了在Docker容器中运行Docker:无法连接到Docker守护程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我创建了一个Dockerfile以在Docker内部运行Docker:

I created a Dockerfile to run Docker inside Docker:

FROM ubuntu:16.04 RUN apt-get update && \ apt-get install -y \ apt-transport-https \ ca-certificates \ curl \ software-properties-common && \ curl -fsSL download.docker/linux/ubuntu/gpg | apt-key add - &&\ apt-key fingerprint 0EBFCD88 RUN add-apt-repository "deb [arch=amd64] download.docker/linux/ubuntu $(lsb_release -cs) stable" && \ apt-get update && \ apt-get install -y docker-ce && \ systemctl enable docker

启动容器并运行docker ps后,我得到了: 无法在unix:///var/run/docker.sock上连接到Docker守护程序。docker守护程序正在运行吗?

After i launched my container and run docker ps i got: "Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?"

我执行了我的容器中的命令dockerd导致:

i executed the command dockerd inside my container resulted:

启动守护程序时出错:初始化网络控制器时出错:获取控制器实例时出错:创建NAT链文档失败:iptables失败:iptables -t nat -N DOCKER:iptables v1.6.0:无法初始化iptables表`nat':权限被拒绝(您必须是root用户)也许iptables或您的内核需要升级。 (退出状态3)

Error starting daemon: Error initializing network controller: error obtaining controller instance: failed to create NAT chain DOCKER: iptables failed: iptables -t nat -N DOCKER: iptables v1.6.0: can't initialize iptables table `nat': Permission denied (you must be root) Perhaps iptables or your kernel needs to be upgraded. (exit status 3)

请告知

推荐答案

如果您真的想在其他Docker容器中运行Docker容器,则应使用Docker提供的现有映像( hub.docker/_/docker ),而不是创建自己的基本映像:选择标记为 dind ( d ocker 中 d ocker)或< docker_version> -dind (如 18.09.0-dind )。如果您想运行自己的映像(尽管不建议这样做),请不要忘记使用-privileged 选项运行它(这就是为什么会出错的原因)。

If you really want to run a Docker container inside an other Docker container, you should use already existing images provided by Docker (hub.docker/_/docker) instead of creating your own base image : choose images tagged as dind (docker in docker) or <docker_version>-dind (like 18.09.0-dind). If you want to run your own image (not recommended though), don't forget to run it with --privileged option (that's why you get the error).

带有 docker 官方图片的示例:

# run Docker container running Docker daemon docker run --privileged --name some-docker -d docker:18.09.0-dind # run hello-world Docker image inside the Docker container previously started docker exec -i -t some-docker docker run hello-world

不过,我同意@DavidMaze的评论以及他提到的参考博客文章(请勿将Docker-in-Docker用于CI ):应尽可能避免使用Docker-in-Docker。

Nevertheless, I agree with @DavidMaze comment and the reference blog post he referred to (Do not use Docker-in-Docker for CI) : Docker-in-Docker should be avoided as much as possible.

更多推荐

在Docker容器中运行Docker:无法连接到Docker守护程序

本文发布于:2023-10-18 12:12:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1504197.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:连接到   容器   程序   Docker

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!