Lesstep
Bitbucket Cloud・Pipelines・2026年11月2日に確認

Bitbucket Pipelines:「Cannot connect to the Docker daemon」

Pipelines のステップに Docker デーモンがあるのは、ステップがそれを頼んだときだけです。無いとき、またはツールが違う場所を探したとき、Docker のクライアントは次のどちらかで止まります。

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Cannot connect to the Docker daemon at tcp://localhost:2375. Is the docker daemon running?

1行目は、たいていステップに Docker デーモンが無いか、ツールがソケットのファイルを直接見にいった場合です。2行目は、Atlassian が Linux Shell ランナーについて書いているものです。

ステップに docker サービスが無い

Atlassian の Bitbucket Pipelines で Docker コマンドを実行するは、ステップのサービスに docker を足すよう書いています。こうするとビルド用のコンテナに Docker CLI が入り、ステップに Docker デーモンが付きます。

pipelines:
  default:
    - step:
        script:
          - docker version
          - docker build -t my-app .
        services:
          - docker

イメージに Docker のクライアントが入っていないと、サービスの無いステップはその前に docker: command not found で止まります。

/var/run/docker.sock を探すツール

Pipelines の Docker のクライアントは、ソケットのファイルを使いません。Atlassian の既定の変数(英語)に DOCKER_HOST(ステップの Docker デーモンの場所)があり、クライアントはそれに従います。DOCKER_HOST を読むツールやライブラリならデーモンが見つかり、設定に /var/run/docker.sock と書いてあるものは見つかりません。ステップで変数を表示してアドレスを確かめ、ツールにそれを教えます。

ソケットを別のコンテナにマウントする -v /var/run/docker.sock:/var/run/docker.sock も、Atlassian のマシンでは通りません。クローン先の外へのボリュームは、Pipelines が断るオプションの1つです(「authorization denied by plugin pipelines」)。

Testcontainers

Testcontainers の Bitbucket Pipelines 向けの説明(英語)が求めるのは2つです。ステップに docker サービスを付けることと、後片付け用のコンテナ Ryuk を切ることです。Pipelines では privileged のコンテナを起動できないためです。Docker のメモリを増やす必要がある場合があるとも書かれています。

pipelines:
  default:
    - step:
        image: maven:3.6.1
        script:
          - export TESTCONTAINERS_RYUK_DISABLED=true
          - mvn clean install
        services:
          - docker
definitions:
  services:
    docker:
      memory: 2048

export の行の代わりに、リポジトリの変数にしてもかまいません。

Linux Shell ランナー:tcp://localhost:2375

セルフホストの Linux Shell ランナーでは、ステップがマシンの上で直接動きます。Atlassian の記事 "Cannot connect to Docker daemon" error while running Docker commands(英語)が2行目のわけを説明しています。マシンの端末では Docker が動くのに、ビルドは tcp://localhost:2375 を探し、Docker は既定ではそこを開けていません。記事は systemd の設定を足して dockerd にそこでも待たせ、読み込み直して Docker を再起動しています。

# /etc/systemd/system/docker.service.d/options.conf
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H unix:// -H tcp://127.0.0.1:2375
sudo systemctl daemon-reload
sudo systemctl restart docker

暗号化したつなぎ方にするときは、代わりにポート 2376 と TLS の証明書を使います。

Runtime v3

Runtime v3 でも、デーモンは docker サービスで付きますが、Docker CLI は入らなくなります(Runtime v3 を有効にして使用する)。ビルド用イメージにクライアントを入れておくか、スクリプトで入れます。

IntelliJ IDEA で Bitbucket Pipelines を見る

Pipeline Inbox for Bitbucket Pipelines は、Lesstep が作っている JetBrains IDE(2024.1 以降)のプラグインです。Bitbucket Cloud の全部のリポジトリのパイプラインを IDE のツールウィンドウに並べ、ステップ、失敗したステップと止まったコマンド、Bitbucket が書くそばから伸びるステップのログを見せます。一覧・ステップ・ログは無料。パイプラインの実行・やり直し・停止は Pro(月 US$1.50・30日の無料試用つき)。

JetBrains Marketplace で入れる

Atlassian・Bitbucket・Bitbucket Pipelines は Atlassian の商標、Docker は Docker, Inc. の商標、IntelliJ IDEA は JetBrains s.r.o. の商標です。このページは Atlassian・Docker・JetBrains のいずれとも提携しておらず、承認も受けていません。

ほかに:「authorization denied by plugin pipelines」(Docker) · 「Container 'docker' exceeded memory limit.」 · push したのに Pipelines が動かない · 「Container 'Build' exceeded memory limit.」 · 「Exceeded build time limit of 120 minutes」 · キャッシュが効かない · 「unexpected system error」 · 「command not found」 · サブモジュールを取ってこない · 「We couldn't clone the repository」 · 「No online runner available」 · 「No space left on device」 · 「Step exceeded processing limits」 · 次のステップにアーティファクトが無い · 前は通ったビルドが今は落ちる · Build setup に時間がかかる · ビルド時間を使い切った · 「Permission denied to update branch」 · 「You have reached your pull rate limit」(Docker Hub) · 「There is an error in your bitbucket-pipelines.yml」 · 「This pipeline was paused」(デプロイ) · 「Host key verification failed」(SSH) · 変数が空になる · IntelliJ IDEA の Bitbucket Pipelines 用プラグインの比較 · English