Docker Integrations

Hi Guys,

I have a problem with integration of docker and jenkins. In Devsecops course section “Demo - Docker Build and Push” it doesnt explain how to create a webhook to push the code from github to dockerhub. I created it manually but i dont know if it works or not. I create a new repository called “numeric-app” and use my dockerhub sh docker build -t username/numeric-app:“”$GIT_COMMIT"" .’ and sh docker push username/numeric-app:“”$GIT_COMMIT"" .’ . After that i create a new credentials for docker-hub using my dockerhub username and password. When i build now on jenkins the build history and console ouptut error shown like this:

docker login -u username -p ******** https://index.docker.io/v1/
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post “http://%2Fvar%2Frun%2Fdocker.sock/v1.24/auth”: dial unix /var/run/docker.sock: connect: permission denied
[Pipeline] // withDockerRegistry
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: docker login failed
Finished: FAILURE

How to solve this? Thank you. Right now i learn and following devsecops course.

Hi @sudiartohsu,
Can you please provide us your Jenkins file

Regard

Hi mmkmou,

pipeline {
agent any

stages {
stage(‘Build Artifact’) {
steps {
sh “mvn clean package -DskipTests=true”
archive ‘target/.jar’
}
}
stage(‘Unit Tests’) {
steps {
sh “mvn test”
}
post {
always {
junit 'target/surefire-reports/
.xml’
jacoco execPattern: ‘target/jacoco.exec’
}
}
}

  stage('Docker Build and Push') {
        steps {
          withDockerRegistry([credentialsId: "docker-hub", url: ""]) {
          sh 'printenv'
          sh 'docker build -t sudi26/numeric-app:""$GIT_COMMIT"" .'
          sh 'docker push sudi26/numeric-app""$GIT_COMMIT""'
          }
        }  
    }
}

}

i also have added “sudo usermod -a -G docker jenkins” . But still didnt work.

Hi @sudiartohsu

Please try the solution provided on this page :
https://iot4beginners.com/how-to-push-a-docker-image-to-the-docker-hub-using-jenkins-pipeline-2022-ci-cd/