Circleci build (local machine) fails when using setup_remote_docker



I use the command-line tool, circleci build, to locally test my config.yml:

version: 2

    working_directory: ~/app
      - image: circleci/node:8.4.0
      - checkout
      - run: node -e "console.log('Hello from NodeJS ' + process.version + '\!')"
      - run: yarn
      - setup_remote_docker
      - run: docker build .

The above config.yml runs perfectly on CircleCI. The docker build command gets executed.

When running circleci build to run it locally, the following error occurs:

====>> Setup a remote Docker engine
Using local docker engine bind-mounted
====>> docker build .
  #!/bin/bash -eo pipefail
docker build .
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.30/build?buildargs=%7B%7D&cachefrom=%5B%5D&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=Dockerfile&labels=%7B%7D&memory=0&memswap=0&networkmode=default&rm=1&shmsize=0&target=&ulimits=null: dial unix /var/run/docker.sock: connect: permission denied
Error: Exited with code 1
Step failed
Task failed

Docker native for Mac is running on my pc, latest version. I can run docker commands on my local terminal, but inside circleci build, it throws the error.

When I use sudo, the build WILL work on my local machine, but fail on CircleCI. See my build logs:

Without sudo on circleci:
With sudo on circleci:

Any ideas how to make this work both locally and on circleci itself?


Since nobody seems to have this problem, or at least nobody took a look at my post, I’ve created a workaround for myself.

In the very first step of the config.yml, I run this command:

if [[ $CIRCLE_ENV == *"localbuild"* ]]; then
  echo "This is a local build. Enabling sudo for docker"
  echo sudo > ~/sudo
  echo "This is not a local build. Disabling sudo for docker"
  touch ~/sudo

Afterwards, you can do this:

eval `cat ~/sudo` docker build .


The first snippet checks if the CircleCI-provided environment variable CIRCLE_ENV contains localbuild. This is only true when running circleci build on your local machine.
If true, it creates a file called sudo with contents sudo in the home directory.
If false, it creates a file called sudo with NO contents in the home directory.

The second snippet opens the ~/sudo file, and executes it with the arguments you give afterwards. If the ~/sudo file contains “sudo”, the command in this example will become sudo docker build ., if it doesn’t contain anything, it will become docker build ., with a space before it, but that will be ignored.

This way, both the local (circleci build) builds and remote builds will work.



I’m curious, have you tried the following:

Don’t use sudo in your config.yml and instead, use sudo when running the local build tool.

Please let me know so we can investigate this more and hopefully not force you to use the if block.

Corresponding Stack Overflow Question for OP:


I can confirm that running sudo circleci build does NOT work. Here’s the version output from the tool I’m using:

circleci version: 0.0.4330-3c7ae21
Build Agent version: 0.0.4331-3c7ae21
built: 2017-10-11T15:12:49+0000


@FelicianoTech I can’t make it run on my machine either is there any helpful information I can share?


This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.