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

robotsnoindex

Platform Notice: Cloud - This article 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.


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 on the runner machine/server/host if it doesn't exist.

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


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

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.
sudo systemctl daemon-reload


4. Restart docker.

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:

{
    "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.

pipelines:
  default:
    - step:
        runs-on: 
          - 'self.hosted'
          - 'linux.shell'
        script:
          - docker version

Last modified on Mar 7, 2025

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.