Is it possible to install and configure Docker on MacOS runner?

Is it possible to install and configure Docker on MacOS runner? Has anyone done it already and an example available?

2 Likes

I’d love to find a solution for this one as well. It’s the only thing blocking us from moving from CircleCI to GH Worfklows

1 Like

Hi,

Many thanks for your feedback!  

According to the official doc, docker is not installed on hosted MacOS runner by default. Please use command to install it, code sample as below:

jobs:
  my_job:
    runs-on: [macOS-latest]
    steps:
      - name: echo
        run: |
          brew install docker-machine docker
          sudo docker –version

More install command can refer to this ticket,  or we can use a self-hosted macos runner to install docker.

dockeronmac.png

I get the following error:

Client: Docker Engine - Community
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
 Version: 19.03.5
 API version: 1.40
 Go version: go1.13.4
 Git commit: 633a0ea
 Built: Thu Nov 14 23:51:40 2019
 OS/Arch: darwin/amd64
 Experimental: false
##[error]Process completed with exit code 1.

@timpetricola I would love to understand how not having docker on mac blocks you from moving from Circle?  I don’t understand needing to run on Mac but wanting to run your builds in a Linux container.

I am working on an iOS application where I’m running E2E tests. To do so I need to first build the application (using XCode, hence the Mac container) and start a server instance with docker.

But of course, for other flows, it’s not an issue :slight_smile:

@timpetricola that is a reasonable scneario.

Unfortuately the docker community licensing is such that we are not able to install the docker for mac on our hosted runners.  We have had some discussions with Docker about doing this but they have held firm on their request that using Docker on a service requires an enterprise license and docker enterprise is not at all supported on macOS.

For Windows Microsoft holds the license for Docker Enterprise on Windows so we do not have any issues there and for Linux we use a specific build of Docker for Linux that is built and maintained by Azure.

1 Like

@chrispatthanks a lot for the explanations!

I got a bit further with Docker on MacOS:

# -------------------------------------------------------------------------------------------------
# What to run
# -------------------------------------------------------------------------------------------------
jobs:
  smoke_macos:

    runs-on: macos-latest

    strategy:
      fail-fast: false
      matrix:
        php:
          - "7.2"
        httpd:
          - "nginx-stable"

    name: "[PHP ${{ matrix.php }}] vs [${{ matrix.httpd }}]"
    steps:

      # ------------------------------------------------------------
      # Checkout repository
      # ------------------------------------------------------------
      - name: Checkout repository
        uses: actions/checkout@v1

      - name: "[Pre] Install Requirements"
        shell: bash
        run: |
          brew install coreutils
          brew install bash
          brew install socat

      - name: "[Pre] Install Docker"
        shell: bash
        run: |
          brew install docker docker-machine-driver-xhyve
          sudo chown root:wheel $(brew --prefix)/opt/docker-machine-driver-xhyve/bin/docker-machine-driver-xhyve
          sudo chmod u+s $(brew --prefix)/opt/docker-machine-driver-xhyve/bin/docker-machine-driver-xhyve
          while ! docker-machine create --driver xhyve default; do
            docker-machine rm -f default
            sleep 1;
          done
          # Export variable (this target)
          eval "$(docker-machine env default)"
          DOCKER_TLS_VERIFY="$( docker-machine env default | grep DOCKER_TLS_VERIFY | sed -e 's/.*="//g' -e 's/"$//g' )"
          DOCKER_HOST="$( docker-machine env default | grep DOCKER_HOST | sed -e 's/.*="//g' -e 's/"$//g' )"
          DOCKER_CERT_PATH="$( docker-machine env default | grep DOCKER_CERT_PATH | sed -e 's/.*="//g' -e 's/"$//g' )"
          DOCKER_MACHINE_NAME="$( docker-machine env default | grep DOCKER_MACHINE_NAME | sed -e 's/.*="//g' -e 's/"$//g' )"
          # Export variable (this other targets)
          # https://help.github.com/en/actions/automating-your-workflow-with-github-actions/development-tools-for-github-actions#set-an-environment-variable-set-env
          echo ::set-env name=DOCKER_TLS_VERIFY::${DOCKER_TLS_VERIFY}
          echo ::set-env name=DOCKER_HOST::${DOCKER_HOST}
          echo ::set-env name=DOCKER_CERT_PATH::${DOCKER_CERT_PATH}
          echo ::set-env name=DOCKER_MACHINE_NAME::${DOCKER_MACHINE_NAME}
          # Show info
          docker-machine ls
          docker-machine env default
          docker version

      - name: "[Pre] Install Docker Compose"
        shell: bash
        run: |
          sudo curl -L https://github.com/docker/compose/releases/download/1.25.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
          sudo chmod +x /usr/local/bin/docker-compose
          docker-compose version

      - name: "[Pre] Setup Docker machine"
        shell: bash
        run: |
          # Setup DNS records
          echo "127.0.0.1 localhost" | sudo tee -a /etc/hosts

          # Portforwarding from DOCKER_HOST to local
          HOST="$( echo "${DOCKER_HOST}" | sed -e 's|^tcp://||g' -e 's|:.*||g' )"
          echo "${HOST}"
          sudo socat -s -d -d tcp-listen:80,reuseaddr,fork tcp:${HOST}:80 &
          sleep 2
          sudo socat -s -d -d tcp-listen:443,reuseaddr,fork tcp:${HOST}:443 &
          sleep 2
          if ! netstat -an | grep -i LISTEN | grep -E '(:80)|(\.80)\s'; then
            netstat -an | grep -i LISTEN;
            false;
          fi
          if ! netstat -an | grep -i LISTEN | grep -E '(:443)|(\.443)\s'; then
            netstat -an | grep -i LISTEN;
            false;
          fi
          host localhost
          curl -sS -I 'http://localhost:80' || true
          curl -sS -I 'https://localhost:443' || true

      - name: "[Info] Show environment"
        shell: bash
        run: |
          env
        if: success() || failure()

      - name: "[Info] Show network"
        shell: bash
        run: |
          netstat -an || true
          ss -tlun || true
        if: success() || failure()

However, the issue I now have is that (even docker-compose was installed successfully and works) no directories are being mounted into my Docker stack.

@timpetricoladid you ever manage to get a workflow running on MacOS with docker.

I have exactly the same scenario at the moment.

Regards,

Stuart

I actually didn’t investigate further as our current setup is working well on CircleCI and there is no rush to change

@chrispat It seems like Docker Desktop Enterprise for Mac is now available, does this unblock the licensing/macOS support issue?

2 Likes