美文网首页
理解docker.sock,未映射sock导致的jenkins无

理解docker.sock,未映射sock导致的jenkins无

作者: kinkyboots | 来源:发表于2017-11-21 23:13 被阅读127次

    在学习Continuous Delivery with Docker and Jenkins
    使用Docker中的Jenkins镜像启动时使用了

    $ docker run -p <host_port>:8080 -v <host_volume>:/var/jenkins_home jenkins:2.60.1
    

    配置成功后尝试运行Jenkins官网的入门example

    Jenkinsfile (Declarative Pipeline)
    pipeline {
        agent { docker 'node:6.3' }
        stages {
            stage('build') {
                steps {
                    sh 'npm --version'
                }
            }
        }
    }
    

    这里的agent是启动一个docker实例
    接下来获取repository成功后容其中docker pull时报错 failed to get default registry endpoint from daemon

    + docker pull node:6-alpine
    Warning: failed to get default registry endpoint from daemon (Cannot connect to the Docker daemon. Is the docker daemon running on this host?). Using system default: https://index.docker.io/v1/
    Cannot connect to the Docker daemon. Is the docker daemon running on this host?
    [Pipeline] }
    [Pipeline] // stage
    [Pipeline] }
    [Pipeline] // node
    [Pipeline] End of Pipeline
    ERROR: script returned exit code 1
    Finished: FAILURE<pre class="console-output" style="box-sizing: border-box; white-space: pre-wrap; word-wrap: break-word; margin: 0px; color: rgb(51, 51, 51); font-size: 13px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">+ docker pull node:6-alpine
    Warning: failed to get default registry endpoint from daemon (Cannot connect to the Docker daemon. Is the docker daemon running on this host?). Using system default: [https://index.docker.io/v1/](https://index.docker.io/v1/)
    Cannot connect to the Docker daemon. Is the docker daemon running on this host?
    
     ERROR: script returned exit code 1
    Finished: FAILURE
    
    

    仔细阅读Jenkins官网Docker指南后发现少了docker.sock的映射

    docker run -d -p 80:8080 \
    -v $(pwd)/jenkinshome:/var/jenkins_home \
    -v /var/run/docker.sock:/var/run/docker.sock \
    jenkinsci/blueocean
    

    成功build

    image.png
    docker.sock是什么?
    阅读了About /var/run/docker.sock

    docker.sock是Docker守护进程的socket接口,通过它我们可以使用创建启动新的docker实例,上面的例子中因为没有映射,导致在container内部没有办法创建Docker image

    相关文章

      网友评论

          本文标题:理解docker.sock,未映射sock导致的jenkins无

          本文链接:https://www.haomeiwen.com/subject/jnugvxtx.html