Docker中的Docker| Github actions - Self Hosted Runner

8mmmxcuj  于 2023-11-17  发布在  Docker
关注(0)|答案(3)|浏览(158)

我尝试在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。

oogrdqng

oogrdqng1#

除了使用套接字,还有一种方法可以通过TCP从容器中的Docker连接到外部Docker。
Linux示例:
运行ifconfig,它将打印在主机节点上安装docker时创建的docker的网络接口。通常命名为docker0,记下此接口的IP地址。
现在,修改/etc/docker/daemon.json并将此tcp://IP:2375添加到hosts部分。重新启动docker服务。
运行带有额外选项的容器:--add-host=host.docker.internal:host-gateway
在任何这样的容器中,地址tcp://host.docker.internal:2375现在指向外部Docker引擎。

ghg1uchk

ghg1uchk2#

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

kx1ctssn

kx1ctssn3#

刚刚发现我最近解决了这个问题。你需要指定Docker组在你主机上的组ID,以便挂载的套接字具有权限。示例可以在这里找到https://github.com/HomeLabHQ/runner

相关问题