【问题标题】:Docker in Docker | Github actions - Self Hosted RunnerDocker 中的 Docker | Github 操作 - 自托管运行器
【发布时间】:2023-03-27 04:50:01
【问题描述】:

我正在尝试为 Kubernetes 上的 Github 操作创建一个自托管运行器。第一步是尝试使用 docker 文件,如下所示:

FROM ubuntu:18.04

# set the github runner version
ARG RUNNER_VERSION="2.283.1"

# update the base packages and add a non-sudo user
RUN apt-get update -y && apt-get upgrade -y && useradd -m docker
RUN useradd -r -g docker nonroot
# install python and the packages the your code depends on along with jq so we can parse JSON
# add additional packages as necessary
RUN apt-get install -y curl jq build-essential libssl-dev apt-transport-https ca-certificates curl software-properties-common

# install docker
RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - \
    && add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable" \
    && apt update \
    && apt-cache policy docker-ce \
    && apt install docker-ce -y

ENV TINI_VERSION v0.19.0
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
RUN chmod +x /tini
RUN usermod -aG docker nonroot
USER nonroot
# set the entrypoint to the start.sh script
ENTRYPOINT ["/tini", "--"]
CMD ["/bin/bash"]

构建完成后,我使用以下命令运行容器:

 docker run -v /var/run/docker.sock:/var/run/docker.sock -it srunner

当我尝试拉取图像时,出现以下错误:

nonroot@0be0cdccb29b:/$ docker run hello-world
docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/create": dial unix /var/run/docker.sock: connect: permission denied.
See 'docker run --help'.
nonroot@0be0cdccb29b:/$

请告知是否有可能在 docker 容器中以非 root 身份运行 docker。

【问题讨论】:

  • 这是在 Kubernetes 上,所以我不确定,但我在 Azure DevOps selft 托管代理和these steps solved the issue上的 VM 上也遇到过类似情况@
  • 它在 Compute Engine(GCP 上的 VM)上对我很有用 @KrzysztofMadej。但我想把它带到 Kubernetes
  • 你试过了吗? techoverflow.net/2017/03/01/…
  • 是的,我试过了

标签: docker kubernetes dockerfile google-kubernetes-engine github-actions


【解决方案1】:

除了使用套接字之外,还有一种方法可以通过 TCP 从容器中的 docker 连接到外部 docker。

Linux 示例:

运行ifconfig,它将打印您在主机节点上安装docker时创建的docker网络接口。它通常命名为docker0,记下该接口的IP地址。

现在,修改 /etc/docker/daemon.json 并将 thistcp://IP:2375 添加到 hosts 部分。重启docker服务。

使用额外选项运行容器:--add-host=host.docker.internal:host-gateway

在任何此类容器内,地址 tcp://host.docker.internal:2375 现在指向外部 docker 引擎。

【讨论】:

  • 感谢 SD,但计划与 Kubernetes 部署一样运行。在这种情况下,可能无法即时修改设置
【解决方案2】:

尝试按照here 的建议将您的用户名添加到 docker 组。
此外,您应该检查您的内核compatibility

【讨论】:

  • 会检查同样的
  • @WytrzymałyWiktor 是的,我使用 DIND 容器来实现相同的目标,并且能够在 Kubernetes 中使用 Github 托管的运行器。供您参考的链接。 https://sanderknape.com/2020/03/self-hosted-github-actions-runner-kubernetes/https://github.com/sokube/github-k8s-runner
猜你喜欢
  • 2021-02-04
  • 2021-10-03
  • 2021-05-14
  • 2020-11-20
  • 2022-08-13
  • 2022-11-21
  • 2022-01-18
  • 2017-12-20
  • 2022-08-15
相关资源
最近更新 更多