【问题标题】:How to connect to docker daemon in Bitbucket pipeline如何连接到 Bitbucket 管道中的 docker 守护进程
【发布时间】:2021-07-11 12:44:47
【问题描述】:

我想在 Bitbucket 管道中运行一个 docker 容器。但是我无法执行任何命令,因为它声称 docker 守护程序没有运行。但是,我没有找到任何方法来启动它。

INFO     Running command 'which docker' in '/opt/atlassian/pipelines/agent/build'
INFO     STDOUT b'/usr/bin/docker\n'
INFO     STDERR b''
INFO     Running command 'docker --version' in '/opt/atlassian/pipelines/agent/build'
INFO     STDOUT b'Docker version 19.03.15, build 99e3ed8\n'
INFO     STDERR b''
INFO     Running command 'systemctl start docker' in '/opt/atlassian/pipelines/agent/build'
INFO     STDOUT b''
INFO     STDERR b'/bin/sh: 1: systemctl: not found\n'
INFO     Running command 'sudo systemctl start docker' in '/opt/atlassian/pipelines/agent/build'
INFO     STDOUT b''
INFO     STDERR b'/bin/sh: 1: sudo: not found\n'
INFO     Trying to remove old Docker container...
INFO     Running command 'docker container rm test_container' in '/opt/atlassian/pipelines/agent/build'
INFO     STDOUT b''
INFO     STDERR b'Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?\n'

我已经读过,以某种方式将外部守护程序通过管道传输到容器中是很常见的,但我找不到任何方法来实现这一点。

那么谁能告诉我这应该如何工作?

顺便说一句,我正在使用“subprocess.Popen(...)”在 python 进程中执行命令。

这是bitbucket-pipelines.yml中对应的步骤:

  - step: &test-docker
      name: Build the docker container and run the tests against it
      script:
      - pip install tox
      - docker info
      - tox -e test-docker
      services:
        - docker

【问题讨论】:

    标签: docker bitbucket-pipelines


    【解决方案1】:

    要在 bitbucket 的管道中启用 docker,只需将其添加到 yml 文件中:

    options:
      docker: true
    
    definitions:
      services:
        docker:
          memory: 3072
    

    然后在您的 X step 部分引用该服务:

    step:
      name: "X"
      services:
        - docker
    

    这对我有用。

    【讨论】:

      【解决方案2】:

      有两种选择: 一种是使用 docker-in-docker 容器。 另一种方法是直接在 bitbucket 管道中构建 docker 映像,启动容器并直接在 localhost 上使用 http 请求从测试中访问服务。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-03-19
        • 1970-01-01
        • 2017-06-14
        • 1970-01-01
        • 2021-10-27
        • 2016-04-04
        • 2020-06-03
        相关资源
        最近更新 更多