0

can someone please let me know on how to pass insecure registry as an argument when using DIND image as runtime container. Please find the below sample script which i had been using as docker run time agent. '''

pipeline {
       agent {label 'jenkins-docker-slave'}
              stages{             
                  stage('maven version'){ 
                         agent {docker { image 'maven:latest'}}                                                         
                     steps{
                        script{                              
                          sh "mvn --version"
                               }           
                          
                         }
                   }
                  stage('docker build'){                          
                         agent {
                                   docker { 
                                           image 'docker:dind'
                                           args '-v /var/run/docker.sock:/var/run/docker.sock'                                           
                                           
                            }
                         }
                     steps{                            
                        script{  
      
                          sh 'docker version'  
                            }
                         }
                    }
 }
}

'''

Docker version works fine but my motive is to set insecure registry as below during the runtime so that i can use docker login and docker push commands successfully.

{
  "insecure-registries": [
    "ec2-52-39-183-6.us-west-2.compute.amazonaws.com:8123"
  ]
}

I want to make the above condition work during the runtime. Can someone please advise on how this can be achived with DIND?

David Maze
  • 130,717
  • 29
  • 175
  • 215
  • Can you use [AWS Certificate Manager](https://docs.aws.amazon.com/acm/latest/userguide/acm-overview.html) to get a valid TLS certificate for the registry, so you don't need this option? – David Maze Sep 16 '20 at 15:15

1 Answers1

1

I have found a solution for my query on my own. Below is the solution:

sh 'docker exec --tty $(docker ps -ql) sh -c "mkdir -p /etc/docker"' 
sh 'docker exec --tty $(docker ps -ql) sh -c "mkdir -p /root/.docker"'
sh '''
    docker exec --tty $(docker ps -ql) sh -c "cat <<EOF > /etc/docker/daemon.json
    {
           "insecure-registries": [
              "ec2-52-36-87-109.us-west-2.compute.amazonaws.com:8123"
                                      ]
     }"
'''

But the only problem is , the above used port 8123 for the docker repository connector is not opened due to which getting the below error.

Error response from daemon

Is there any way to open ports within docker container to get this worked?

Dov Benyomin Sohacheski
  • 7,133
  • 7
  • 38
  • 64