I am using a custom docker image to run a github workflow, whose ultimate purpose is to build and push an image to a GCR. I am using a custom image because the build process needs a lot of prerequisites installed. I want to speed up the CI workflow and I want the Dockerfile to act as a manifest for what the build environment needs.
The issue is connecting to docker.sock. I get a permission denied error. Here is the minimal Dockerfile:
FROM ubuntu:latest
RUN apt-get update &&
apt-get install -y
curl
&& apt-get clean
&& rm -rf /var/lib/apt/lists/*
RUN curl -fsSL https://get.docker.com -o get-docker.sh
RUN sh get-docker.sh
Here is the minimal workflow file:
name: Deploy to staging
on:
push:
tags:
- '*'
jobs:
deploy:
runs-on: ubuntu-latest
container:
image: eu.gcr.io/my-image
credentials:
username: _json_key
password: ${{ secrets.TOKEN }}
env:
...
steps:
- name: call docker
run: docker images
I can reproduce the issue locally by running the container and doing docker images
(or any docker command) it can’t connect to the docker daemon:
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
I can solve this locally by mounting the host docker.sock with:
docker run -it -v /var/run/docker.sock:/var/run/docker.sock
But I can’t mount docker.sock do that on a github runner (I assume for security reasons). The issue is not adding the user to the docker group. I tried that. I believe the issue is inherent in trying to run docker commands on a custom image in a github workflow.
How can I solve this problem? Is there a way in github actions, or is another CI tool more suitable?