詹金斯:无法连接到Docker Daemo

发布于 2025-01-30 00:30:35 字数 1048 浏览 4 评论 0 原文

我想用詹金斯创建一个码头图像,但无法连接到Docker守护程序。

这是我的管道

pipeline {
    agent any
    options { buildDiscarder(logRotator(numToKeepStr:'5'))}
    environment {DOCKERHUB_CREDENTIALS = credentials('tfkben-dockerhub')}
    stages {
            stage('build'){  steps {  sh 'docker build -t tfkben/ben:latest .' }  }
            stage('Login'){  steps {  sh 'echo $DOCKERHUB_CREDENTIALS_PSW | docker login -u $DOCKERHUB_CREDENTIALS_USR --password-stdin ' }}
            stage('Push'){  steps {  sh 'docker push tfkben/ben:latest'}   }                                 
         }                           
            post { always { sh 'docker logout' }}

} 我的dockerfile:

FROM python:3.11-rc-bullseye

WORKDIR /app

COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt

COPY . .

CMD [ "python3", "manage.py", "runserver", "0.0.0.0:8000"]
and this is the error message :
  • docker build -t tfkben/ben:最新。 无法通过TCP:// Docker:2376连接到Docker守护程序。 Docker守护程序在运行吗?

i wanted to create a docker image with jenkins but Cannot connect to the Docker daemon .

this is my pipeline

pipeline {
    agent any
    options { buildDiscarder(logRotator(numToKeepStr:'5'))}
    environment {DOCKERHUB_CREDENTIALS = credentials('tfkben-dockerhub')}
    stages {
            stage('build'){  steps {  sh 'docker build -t tfkben/ben:latest .' }  }
            stage('Login'){  steps {  sh 'echo $DOCKERHUB_CREDENTIALS_PSW | docker login -u $DOCKERHUB_CREDENTIALS_USR --password-stdin ' }}
            stage('Push'){  steps {  sh 'docker push tfkben/ben:latest'}   }                                 
         }                           
            post { always { sh 'docker logout' }}

}
my Dockerfile :

FROM python:3.11-rc-bullseye

WORKDIR /app

COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt

COPY . .

CMD [ "python3", "manage.py", "runserver", "0.0.0.0:8000"]
and this is the error message :
  • docker build -t tfkben/ben:latest .
    Cannot connect to the Docker daemon at tcp://docker:2376. Is the docker daemon running?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

只怪假的太真实 2025-02-06 00:30:35

@Toufik Benkhelifa看来,您的Jenkins代理商中没有安装Docker。您的Jenkins代理商在哪里?这里有几种可能性。

  1. 如果您将任何Linux发行版OS(Ubuntu,Redhat,CentOS等)作为Jenkins代理,则可以在该代理中明确安装Docker Daemon。

参考: https://docs.docker.com/engine/engine/install/

  1. 如果您是将代理作为Docker容器运行,然后您可以做类似于下面的事情,

让您说您同时将Jenkins Master和Jenkins Agent作为Docker节点运行。

在哪里,

  • 詹金斯大师实际上在Docker内运行,因为Docker容器
  • Jenkins Agent在Docker内部作为Docker容器在Docker内部运行,
  • 现在Jenkins Master正在通过TCP:///host.docker.internal.internal.internal:2375与Host Docker通过Docker Docker进行通信
  • 。 Jenkins Master与Docker Demon连接,然后可以通过恶魔安全地与该Docker主机内运行的任何容器进行通信詹金斯特工。

现在,将Jenkins Master与Docker主持人Daemon链接。为此,您需要使用“ docker插件for jenkins” https://plugins.jenkins.jenkins.jenkins.jenkins .io/docker-plugin/

此Docker插件的目的是能够使用Docker主机动态地提供Docker容器作为Jenkins Agent Node,让该运行单个构建,然后将其拆除,然后拆下来节点,没有构建过程(或詹金斯的作业定义),需要对Docker的任何认识。

安装插件后,我们要做的就是配置Jenkins,以添加Jenkins的新云 - >管理 - >系统配置并将新云添加为“ Docker”

,最后,如前所述,Docker恶魔将在上运行,

tcp://host.docker.internal:2375

其中需要是Docker主机URI

参考:https://blog.executeautomation.com/running-jenkins-build-agent-within-docker-container-part- A/

@Toufik Benkhelifa It seems you don't have docker installed in your jenkins agent. Where is your Jenkins agent is resided? There are couple of possibilities here.

  1. If you are using any Linux distros OS(Ubuntu, Redhat, centos etc) as Jenkins agent, then you can install docker daemon explicitly in that agent.

Reference: https://docs.docker.com/engine/install/

  1. If you are running the agent as a docker container, then you can do something similar to below

Lets say you have both Jenkins master and Jenkins agent running as docker nodes.

Where,

  • Jenkins Master is actually running within Docker as a Docker container
  • Jenkins Agent is running within Docker as a Docker container
  • Now the Jenkins Master is communicating with the host Docker via Docker Demon in tcp://host.docker.internal:2375
  • Once the Jenkins Master is connected with Docker Demon, it can then safely communicate with any containers running within that Docker host via the Demon, since it will have all the networking information to talk with different containers, in this case it's going to be a Docker container running Jenkins agent.

Now, Link Jenkins Master with Docker Host Daemon. In order to do that, you need to use "Docker plugin for Jenkins" https://plugins.jenkins.io/docker-plugin/

The aim of this docker plugin is to be able to use a Docker host to dynamically provision a docker container as a Jenkins agent node, let that run a single build, then tear-down that node, without the build process (or Jenkins job definition) requiring any awareness of docker.

Once the plugin is installed, all we need to do is to configure Jenkins to add new cloud from Jenkins -> Manage -> System configuration and add new cloud as 'Docker'

Finally, as mentioned earlier, the Docker demon will be running on

tcp://host.docker.internal:2375

which needs to be the Docker Host URI

Reference : https://blog.executeautomation.com/running-jenkins-build-agent-within-docker-container-part-a/

谈情不如逗狗 2025-02-06 00:30:35

这很可能是由于您的Jenkins代理商没有Docker守护程序在其中。

如果代理本身作为Docker容器运行,则需要确保其使用具有“ Docker-In-indocker”的图像(DIND)

It is likely due to your Jenkins agent not having a Docker daemon running within it.

If the agent itself is running as a Docker container, then you need to ensure that it uses an image that has “Docker-in-Docker” (dind)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文