如何连接到 Bitbucket 管道中的 docker 守护进程

Nay*_*aro 3 docker bitbucket-pipelines

我想在 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'
Run Code Online (Sandbox Code Playgroud)

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

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

顺便说一下,我正在使用“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
Run Code Online (Sandbox Code Playgroud)

AZZ*_*Z_B 5

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

options:
  docker: true

definitions:
  services:
    docker:
      memory: 3072
Run Code Online (Sandbox Code Playgroud)

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

step:
  name: "X"
  services:
    - docker
Run Code Online (Sandbox Code Playgroud)

这对我有用。