![](/img/trans.png)
[英]How to run Renovate inside a Ubuntu 20.04 Docker container?
[英]Run docker inside ubuntu container
2 天我尝试在 ubuntu 容器中运行 docker:
docker run -it ubuntu bash
root@e65411d2b70a:/# docker -v
Docker version 19.03.6, build 369ce74a3c
docker run hello-world
时出现了一些问题root@5ac21097b6f6:/# docker run hello-world
docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
See 'docker run --help'.
在服务列表中不是 docker:
root@5ac21097b6f6:/# service docker start
docker: unrecognized service
root@5ac21097b6f6:/# service --status-all
[ - ] apparmor
[ + ] cgroupfs-mount
[ - ] dbus
[ ? ] hwclock.sh
[ - ] procps
[ ? ] ubuntu-fan
当尝试运行dockerd
:
root@5ac21097b6f6:/# dockerd
INFO[2020-04-23T07:01:11.622627006Z] Starting up
INFO[2020-04-23T07:01:11.624389266Z] libcontainerd: started new containerd process pid=154
INFO[2020-04-23T07:01:11.624460438Z] parsed scheme: "unix" module=grpc
INFO[2020-04-23T07:01:11.624477203Z] scheme "unix" not registered, fallback to default scheme module=grpc
INFO[2020-04-23T07:01:11.624532871Z] ccResolverWrapper: sending update to cc: {[{unix:///var/run/docker/containerd/containerd.sock 0 <nil>}] <nil>} module=grpc
INFO[2020-04-23T07:01:11.624560679Z] ClientConn switching balancer to "pick_first" module=grpc
INFO[2020-04-23T07:01:11.664827037Z] starting containerd revision= version="1.3.3-0ubuntu1~18.04.2"
ERRO[2020-04-23T07:01:11.664943052Z] failed to change OOM score to -500 error="write /proc/154/oom_score_adj: permission denied"
...
INFO[2020-04-23T07:01:11.816951247Z] stopping event stream following graceful shutdown error="context canceled" module=libcontainerd namespace=plugins.moby
failed to start 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.1: can't initialize iptables table `nat': Permission denied (you must be root)
Perhaps iptables or your kernel needs to be upgraded.
(exit status 3)
不明白为什么Permission denied
if user root
。
安装sudo
并将 root 添加到该组,但它没有帮助。
apt-get install sudo
usermod -a -G sudo root
- sudo dockerd
有保存问题。
如何在 ubuntu 容器内工作 docker? 你有想法吗?
附言。 我知道 docker-in-docker,我需要 docker inside ubuntu-container
附言。 我知道-v /var/run/docker.sock:/var/run/docker.sock
- 但需要在 ubuntu-container 中独立 docker 服务。
在 docker 中运行 docker 时,容器必须在您的主机上使用 docker 引擎。
这是一个简单的工作设置:
1) 创建一个安装了 docker CLI 的 dockerfile。 我用的是官方的compose图片,所以你也有docker-compose
FROM docker/compose:1.25.5
WORKDIR /app
ENTRYPOINT ["/bin/sh"]
2)运行时,安装docker sock
$ docker build -t dind .
$ docker run --rm -it -v /var/run/docker.sock:/var/run/docker.sock dind
在容器内形成,您现在拥有 docker。 尝试运行docker ps
如果你想在没有-v /var/run/docker.sock:/var/run/docker.sock
的情况下在 docker 中做 docker ,那么恐怕没有好的方法可以做到这一点。 从主机共享 docker 套接字是使 docker 容器在另一个 docker 容器中运行的经典方法。
在过去的几天里,我一直在尽最大努力像你一样在容器中运行容器。 浪费了很多时间。 到目前为止,大多数人建议我做一些事情,比如使用不适用于我的情况的 docker 的 DIND 图像,因为我需要主容器是 Ubuntu 操作系统,或者运行一些特权命令和 map 守护程序套接字到容器中,像-v /var/run/docker.sock:/var/run/docker.sock
(这对我或我试过的任何 Ubuntu 操作系统都不起作用。原因是,基于 Ubuntu 操作系统的主容器不带有 systemd,这对于像普通本地机器一样方便地运行 docker 容器很重要)
我找到的解决方案是在我的 Ubuntu 20.04 系统上使用 Nestybox,效果最好。 如果您的本地系统是 ubuntu(他们最支持),它的执行也非常简单,因为容器运行时是专门为此类应用程序设计的。 它还具有最灵活的选项。 截至 2022 年 11 月,免费版的 Nestybox 可能是最好的方法。强烈建议您尝试一下,而不要理会其他人建议的所有繁琐设置。 他们有许多预构建的解决方案,可以通过简单的命令行来满足此类特定需求。
Nestybox 为新创建的 docker 容器提供了特殊的运行环境,他们还提供了一些 docker 和内置 systemd 的 ubuntu/common OS 镜像。 他们的目标是让主容器function安全的和虚拟机一模一样。 您也可以从字面上将 ssh 放入 ubuntu 主容器中,而无法访问主机中的任何内容。 从您的主容器中,您可以像普通本地系统一样创建各种容器。 systemd 对于您在容器内方便地设置 docker 非常重要。
执行 sysbox 的一个简单的常用命令:
dock run --runtime=sysbox-runc -it any_image
如果你认为这就是你要找的东西,你可以在他们的 github 找到更多信息: https://github.com/nestybox/sysbox
有关如何部署简单 sysbox 运行时环境容器的说明的快速链接: https://github.com/nestybox/sysbox/blob/master/docs/quickstart/README.md
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.