Build images as part of Jenkins Worker on Kubernetes

0 votes

I have Jenkins deployed on kubernetes (AWS EKS), and a node designated for the jenkins pipelines tasks. I have a pipeline which I want to build a docker image, so here is how my pipelines looks:

pipeline {
    agent {
        kubernetes {
            defaultContainer 'jnlp'
            yaml """
apiVersion: v1
kind: Pod
spec:
  nodeSelector:
    illumex.ai/noderole: jenkins-worker
  containers:
  - name: docker
    image: docker:latest
    imagePullPolicy: Always
    command:
    - cat
    tty: true
    volumeMounts:
    - mountPath: /var/run/docker.sock
      name: docker-sock
  volumes:
  - name: docker-sock
    hostPath:
      path: /var/run/docker.sock
"""
        }
    }

    stages {
        stage('build') {
            steps {
                container('system') {
                        sh """
                        docker system prune -f
                        """

However, my job fails with:

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

I think it's permissions issue. However, since the containers are created as part of the pipeline, so for which user I should give permission?

Jan 18, 2023 in AWS by Tejashwini
• 3,820 points

edited 5 days ago 9 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP