简体   繁体   中英

Get error: permission denied when building docker image using jenkins

I configed a jenkins pipeline to build a project that get from github. But I got an error at step 2 - Build image. Then, I tried to add user admin (of jenkins) to group "docker", and I can run build command successfully without error when login by user admin in the kubernetes master vm, however still error with jenkins. I used blueocean plugin for creating the pipeline. Do you know how to fix this ?

在此处输入图片说明

UPDATE: Please see my jenkinsfile

pipeline {

  environment {
    registry = "192.168.64.162:5000/justme/myweb"
    dockerImage = ""
  }

  agent any

  stages {

    stage('Checkout Source') {
      steps {
        git 'https://github.com/taibc/playjenkins.git'        
      }
    }

    stage('Build image') {      
      steps{

        script {
          dockerImage = docker.build registry + ":$BUILD_NUMBER"
        }
      }
    }

    stage('Push Image') {
      steps{
        script {
          docker.withRegistry( "" ) {
            dockerImage.push()
          }
        }
      }
    }

    stage('Deploy App') {
      steps {
        script {
          kubernetesDeploy(configs: "myweb.yaml", kubeconfigId: "mykubeconfig")
        }
      }
    }

  }

}

I resolve this problem by installing Jenkins to another server (not belong to kubernetes cluster). But, I got another problem when deploying app as the link: https://github.com/jenkinsci/kubernetes-cd-plugin/issues/122

Here my yaml file

---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
    app: myweb
  name: myweb
spec:
  replicas: 1
  selector:
    matchLabels:
      app: myweb
  template:
    metadata:
      labels:
        app: myweb
    spec:
      containers:
      - image: 192.168.94.162:5000/justme/myweb:1
        imagePullPolicy: Always
        name: myweb

---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: myweb
  name: myweb
spec:
  ports:
  - nodePort: 32223
    port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: myweb
  type: NodePort

Here my jenkinsscript

pipeline {

  environment {
    registry = "192.168.94.162:5000/justme/myweb"
    dockerImage = ""
  }

  agent any

  stages {

    stage('Checkout Source') {
      steps {
        git 'https://github.com/taibc/playjenkins.git'        
      }
    }

    stage('Build image') {      
      steps{

        script {
          dockerImage = docker.build registry + ":$BUILD_NUMBER"
        }
      }
    }

    stage('Push Image') {
      steps{
        script {
          docker.withRegistry( "" ) {
            dockerImage.push()
          }
        }
      }
    }

    stage('Deploy App') {
      steps {
        script {
          kubernetesDeploy(configs: "myweb.yaml", kubeconfigId: "mykubeconfig")
        }
      }
    }

  }

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM