I have a docker image that is built from the ubuntu image and all I add is gradle and openjdk11

My jenkinsfile defines the containerTemplate as this:

podTemplate(label: 'java11builder', containers: [
    containerTemplate(name: 'java11builder', image: 'java11builder', command: 'cat', ttyEnabled: true )
volumes: [
    hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock')

Then I run this:

stage('Build/Test') {
  container('java11builder') {
      ) {
          sh """
                useradd -ms /bin/bash -G docker elastic
                su elastic -c "docker ps"

Then I get:

Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.39/containers/json: dial unix /var/run/docker.sock: connect: permission denied

Only reason I'm running as this elastic user is to run this task that does integration tests and also builds and pushes the image to docker. The integration tests uses embedded-elasticsearch and it complains about starting elasticsearch under root.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.