-1

I am getting error pushing the docker image:

denied: requested access to the resource is denied

unauthorized: authentication required


script returned exit code 1

The Jenkinsfile stage:

        stage('upload docker') {
            steps {
                sh "./upload_docker.sh"
            }
        }

In the upload_docker file:

docker push username/repo:3

I added the user to the docker group.

I added Jenkins to the docker group.

I added Jenkins to the user group and vice versa.

I changed the permission of the docker config file to allow all.

2 Answers 2

3

You need to login to docker hub before you can push your image to it.

3
  • I logged in from ubuntu user.
    – omeraiman
    Commented Feb 8, 2020 at 10:41
  • 1
    Check if you're logged in Jenkins, try the following here
    – Ghonima
    Commented Feb 8, 2020 at 10:46
  • It worked! I logged in to the instance and I changed the user to Jenkins user. then I added the credentials again. but is it the best way to do that? or should I follow the method below?
    – omeraiman
    Commented Feb 8, 2020 at 18:24
2

In order to push docker image to a private registry, you will need to:

  1. Install docker-workflow plugin.
  2. Create Username/password credential.
  3. Wrap your code to push to docker registry like
docker.withRegistry('https://registry.example.com', 'credentials-id') {

    def customImage = docker.build("my-image:${env.BUILD_ID}")

    /* Push the container to the custom Registry */
    customImage.push()
}

Reference from Jenkins docs

Not the answer you're looking for? Browse other questions tagged or ask your own question.