Issue
I am trying to push a docker image to a private registry without any authentication configured. Below are how the jenkinsfile stages look like.
Without the writeFile command in the deploy stage I get no such host error
docker push <private-vm-name>:5000/temp/prototype-be:v1
The push refers to repository [<private-vm-name>:5000/temp/prototype-be]
Get https://<private-vm-name>:5000/v2/: dial tcp: lookup <private-vm-name> on 127.0.0.11:53: no such host
With the writeFile command I get an AccessDenied exception
java.nio.file.AccessDeniedException: /etc/docker
Could someone guide me on how could these errors be resolved in order to push to a private docker registry?
Thanks.
Jenkinsfile stages
stage('Building docker image') {
steps{
script {
dockerImage = docker.build registry + ":v1"
}
}
}
stage('Pushing docker image') {
steps{
script {
writeFile file:"/etc/docker/daemon.json", text: "{
"insecure-registries": [
"<private-vm-name>:5000"
]
}"
docker.withRegistry( 'http://<private-vm-name>:5000') {
dockerImage.push()
}
}
}
}
Solution
As a workaround I executed the jenkins-server dind
docker image with --insecure-registries
flag. Since the docker container spawned by jenkins was now aware of the private docker registry, the above docker push command worked. Note I also changed the jenkins push command to use the server's ip address instead of the host-name so that I don't need to edit /etc/hosts.
Answered By - Andy Dufresne
Answer Checked By - Willingham (JavaFixing Volunteer)