Maven image can not build docker image (/var/run/docker.sock)

Drone server and agents are deployed in GKE.

Agent is deployed with the following (mounting the /var/run/docker.sock from host):

spec:
  containers:
  - name: agent
    image: drone/agent:0.8
    imagePullPolicy: Always
    volumeMounts:
      - mountPath: /var/run/docker.sock
        name: docker-socket
    env:
      - name: "DRONE_SERVER"
        value: $(SERVER_SERVICE_HOST):9000
      - name: "DRONE_SECRET"
        value: "redacted"
  volumes:
    - name: docker-socket
      hostPath:
        path: /var/run/docker.sock

My .drone.yaml (which uses Maven with fabric8-maven-plugin to build the docker image):

pipeline:
  build-image:
    image: maven:3.5.3-jdk-8
    commands:
      - mvn package fabric8:build

I see the following error which indicates the maven:3.5.3-jdk-8 container is not able to access /var/run/docker.sock.

[ERROR] Failed to execute goal io.fabric8:fabric8-maven-plugin:3.5.38:build (default-cli) on project margarita: Execution default-cli of goal io.fabric8:fabric8-maven-plugin:3.5.38:build failed: No <dockerHost> given, no DOCKER_HOST environment variable, no read/writable '/var/run/docker.sock' or '//./pipe/docker_engine' and no external provider like Docker machine configured -> [Help 1]

How can I fix this?

Thanks in advance.

That is because /var/run/docker.sock does not exist inside the maven:3.5.3-jdk-8 container. If you want to make the socket available, you need to mount it as a volume in your .drone.yml file. You can find examples for this in the docs.

1 Like