Bitbucket Cloud Pipelines Linux Shell runners - "Cannot connect to Docker daemon" error while running Docker commands

Platform Notice: Cloud Only - This article only applies to Atlassian products on the cloud platform.

Summary

While running Docker commands in Bitbucket Cloud Pipelines Linux Shell runners, one may encounter the following error. The Docker commands will be accessible from the runner's host terminal but fail on the Bitbucket runners' build.

1 Cannot connect to the Docker daemon at tcp://localhost:2375. Is the docker daemon running

Solution

The TCP endpoint tcp://localhost:2375 is turned off by default. The Solution is to expose the Docker on the runners host using the below-mentioned steps:

1. Create the following directory if it doesn't exist.

1 sudo mkdir -p /etc/systemd/system/docker.service.d

2. Create options.conf configuration file with the following content.

1 2 3 4 5 6 sudo nano /etc/systemd/system/docker.service.d/options.conf #content [Service] ExecStart= ExecStart=/usr/bin/dockerd -H unix:// -H tcp://127.0.0.1:2375

3. Reload the systemd daemon.

1 sudo systemctl daemon-reload

4. Restart docker.

1 sudo systemctl restart docker

5. If you want to have an encrypted connection, then you should replace port 2375 with 2376, and set up certificates and daemon.json configuration files in /etc/docker/certs/ and /etc/docker/daemon.json. Example:

1 2 3 4 5 6 7 { "tlsverify": true, "tlscacert": "/etc/docker/certs/ca-cert.pem", "tlscert": "/etc/docker/certs/server-cert.pem", "tlskey": "/etc/docker/certs/server-key.pem", "host": "tcp://127.0.0.1:2376" }

6. Rerun the Docker commands in Bitbucket Linux shell-based pipeline runners; they should work without any errors.

1 2 3 4 5 6 7 8 pipelines: default: - step: runs-on: - 'self.hosted' - 'linux.shell' script: - docker version

Updated on February 25, 2025

Still need help?

The Atlassian Community is here for you.