1

I'm using Jkube maven plugin to generate a Docker image via a Jenkins pipeline on AWS EC2 instance under Ubuntu.
When pipeline executes mvn clean install k8s:build I'm getting this error :

[ERROR] Failed to execute goal org.eclipse.jkube:kubernetes-maven-plugin:1.3.0:build (default-cli) on project social-carpooling-frontend: Execution default-cli of goal org.eclipse.jkube:kubernetes-maven-plugin:1.3.0: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]

And this is the Jenkins pipeline :

pipeline {
  agent any
  stages {
    stage('Docker Check Stage') {
      steps {
        sh '/home/bitnami/downloads/apache-maven-3.8.1/bin/mvn clean install k8s:build -Premote'
      }
    }
  }
}

When I log using ssh to this machine and execute docker -v it says Docker version 20.10.0, build 7287ab3

So Docker is really installed and daemon is started, but when I trigger it via maven it seems not to find it ! Any ideas ?

Ghassen
  • 591
  • 1
  • 15
  • 33

1 Answers1

1

The problem was due to the user who's running maven command which doesn't have access to docker.sock

The solution is to modify the read/write permission on docker.sock this way :

sudo chmod 776 /var/run/docker.sock
Ghassen
  • 591
  • 1
  • 15
  • 33
  • Bdw, you can also use Eclipse JKube with JIB Build strategy `mvn k8s:build -Djkube.build.strategy=jib`. This comes really handy in CI where you don't need a docker daemon to build+push image to some registry. – Rohan Kumar Jun 28 '21 at 17:25
  • 1
    @RohanKumar I think actually the plugin is not supporting Dockerfile mode when using jib strategy because I'm getting this error : `Failed to execute the build: Error when building JIB image: Dockerfile mode is not supported with JIB build strategy` – Ghassen Jun 29 '21 at 23:06
  • oh, I'm sorry. Dockerfile mode is not available with JIB. It only works with zero configuration or XML image configuration – Rohan Kumar Jun 30 '21 at 05:03
  • No problem, I switched to XML image config mode and it's fine, but I couldn't find the equivalent for COPY cmd in XML mode ! – Ghassen Jun 30 '21 at 11:51
  • We have [assembly mechanism](https://www.eclipse.org/jkube/docs/kubernetes-maven-plugin#build-assembly) which generates a single COPY instruction. You can find an example in this [blogpost](https://itnext.io/understanding-kubernetes-maven-plugins-image-xml-configuration-e98ef633e231) – Rohan Kumar Jun 30 '21 at 11:58
  • From v1.4.0 , we would also be able to support multi layers images via XML configuration: https://github.com/eclipse/jkube/pull/724 – Rohan Kumar Jun 30 '21 at 11:59