Unable to run docker commands from the pipelines build using docker desktop on macOS

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

Summary

Unable to run docker commands from the pipelines build using docker desktop on macOS.  The build error is:

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

Environment

MacOS Runner in Bitbucket Pipelines running Docker commands.

Diagnosis

  1. Install docker desktop. Add a macOS runner.

  2. Use a similar pipelines configuration: 

    1 2 3 4 5 6 7 8 9 10 pipelines:   default:     - parallel:       - step:         name: 'Test'           runs-on:             - self.hosted             - macos           script:           - docker info
  3. The build error is:

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

Cause

The Mac OS Docker Desktop does not listen to network requests by default.  

Solution

Use socat to relay the docker commands to the local client.  Here is an example command:

1 socat TCP-LISTEN:2375,reuseaddr,fork UNIX-CONNECT:/var/run/docker.sock &

This command will run a daemon in the background for the time that the terminal session is running.  To see the command, run the jobs command.  To make this a permanent daemon, you will need to use launchd.  Here is an example launchd plist:

/Library/LaunchAgents/com.atlassian.pipelines.socat.plist

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>com.atlassian.pipelines.socat</string> <key>ProgramArguments</key> <array> <string>/usr/local/bin/socat</string> <string>TCP-LISTEN:2375,reuseaddr,fork</string> <string>UNIX-CONNECT:/var/run/docker.sock</string> </array> <key>KeepAlive</key> <true/> <key>RunAtLoad</key> <true/> </dict> </plist>

Updated on March 13, 2025

Still need help?

The Atlassian Community is here for you.