Failure - Authentication is required to pull public docker images from Dockerhub registry - docker

I am using Jenkins Custom Build Environment Plugin (1.6.5) to build images from a Dockerfile inside the slave container checked in along with the source code.
Slaves running on Docker version 1.9.1, build ab77bde/1.9.1
My Dockerfile is as below which is able to pull from official ubuntu image but fails to pull from official node.js image -
FROM node:boron
# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
On Jenkins job execution I get below failure -
$ docker build --file /data/name-jenkins/workspace/TestJobs/BuildFromSCM/Dockerfile /data/name-jenkins/workspace/TestJobs/BuildFromSCM
Sending build context to Docker daemon 149.5 kB
Sending build context to Docker daemon 149.5 kB
Step 1 : FROM node:boron
Trying to pull repository registry.access.redhat.com/node ... failed
Trying to pull repository docker.io/library/node ... failed
Authentication is required.
FATAL: Failed to build docker image from project Dockerfile
java.lang.RuntimeException: Failed to build docker image from project Dockerfile
at com.cloudbees.jenkins.plugins.docker_build_env.Docker.buildImage(Docker.java:134)
at com.cloudbees.jenkins.plugins.docker_build_env.DockerfileImageSelector.prepareDockerImage(DockerfileImageSelector.java:46)
at com.cloudbees.jenkins.plugins.docker_build_env.DockerBuildWrapper.setUp(DockerBuildWrapper.java:169)
at hudson.model.Build$BuildExecution.doRun(Build.java:156)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:534)
at hudson.model.Run.execute(Run.java:1741)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:98)
at hudson.model.Executor.run(Executor.java:410)
Finished: FAILURE
I am able to build the Docker image on my local machine though. I confirmed that the Jenkins slave user has sudo permissions.

I found an issue in .docker/config.json on my slave machine where I accidentally set my dockerhub credentials which caused in failure in pulling public images with a generic user I was using to build Jenkins job.
{
"ServerURL": "https://index.docker.io/v1",
"Username": "myusername",
"Secret": "passw0rd1"
}

You may need a certificate of the docker-hub, which is a ca.crt file put in:
/etc/docker/certs.d/

Related

Pull access denied for registry.gitlab.com when the project is transfered to a group in Gitlab.com

Recently I have transfered a private project to a group in Gitlab. The problem is that the gitlab-runner fails at pulling an image from gitlab.registry.com. Does anybody know why it's complaining now?. No changes were made to the file .gitlab-ci.yml, the only difference is that the project was moved to a group via transfer functionality in Gitlab.com.
Here is .gitlab-ci.yml
stages:
- version
version:
stage: version
image: registry.gitlab.com/mbuchleitner/go-semrel-gitlab:v0.21.1
script:
- git fetch --tags
- release next-version --bump-patch > .next-version
artifacts:
paths:
- .next-version
only:
- master
Here is the failed job:
Running with gitlab-runner 13.6.0 (8fa89735)
on docker-auto-scale 0277ea0f
Preparing the "docker+machine" executor
00:12
Using Docker executor with image registry.gitlab.com/mbuchleitner/go-semrel-gitlab:v0.21.1 ...
Authenticating with credentials from job payload (GitLab Registry)
Pulling docker image registry.gitlab.com/mbuchleitner/go-semrel-gitlab:v0.21.1 ...
ERROR: Job failed: Error response from daemon: pull access denied for registry.gitlab.com/mbuchleitner/go-semrel-gitlab, repository does not exist or may require 'docker login' (docker.go:142:0s)
Here is the previous OK job:
Running with gitlab-runner 13.6.0 (8fa89735)
on docker-auto-scale 0277ea0f
Preparing the "docker+machine" executor
00:13
Using Docker executor with image registry.gitlab.com/mbuchleitner/go-semrel-gitlab:v0.21.1 ...
Authenticating with credentials from job payload (GitLab Registry)
Pulling docker image registry.gitlab.com/mbuchleitner/go-semrel-gitlab:v0.21.1 ...
Using docker image sha256:7c4df241bfce32bb7289a3b4c070a717789989773e6c559a8961ea58d3bc54b0 for registry.gitlab.com/mbuchleitner/go-semrel-gitlab:v0.21.1 with digest registry.gitlab.com/mbuchleitner/go-semrel-gitlab#sha256:5d0cd7209456b7bd3a5467d21de3c78b78d763d8ae90612299cd8bb2495d0542 ...
Preparing environment
00:02
Running on runner-0277ea0f-project-8575915-concurrent-0 via runner-0277ea0f-srm-1606329676-ea714745...
Getting source from Git repository
00:03
$ eval "$CI_PRE_CLONE_SCRIPT"
Fetching changes...
Initialized empty Git repository in /builds/carlosrivas/club/.git/
Created fresh repository.
Checking out 896a4cc3 as master...
Skipping Git submodules setup
Executing "step_script" stage of the job script
00:02
$ git fetch --tags
$ release next-version --bump-patch > .next-version
Uploading artifacts for successful job
00:01
Uploading artifacts...
.next-version: found 1 matching files and directories
Uploading artifacts as "archive" to coordinator... ok id=872692037 responseStatus=201 Created token=4bdJi9Hg
Cleaning up file based variables
00:01
Job succeeded
Our setup started failing similarly with seemingly no change at all, unlike your case where you moved the registry. We are using local gitlab-runners with docker executors on the same machine that hosts the registry. Docker pull started failing, despite valid authentication to the container registry; tried .docker/config.json on the gitlab-runner user, DOCKER_AUTH_CONFIG in the project's web UI settings and DOCKER_AUTH_CONFIG in .gitlab-ci.yml, none of which worked. In the end I had to modify the runner's pull_policy to if-not-present so that the image can be found in the local cache.

Unknown Manifest after Docker pull in build pipeline when committing to GitLab

After pushing a commit to GitLab the build pipeline starts to check the new commit. Build and Test stage run successfully. But the Deploy stage stops with the following error:
Running with gitlab-runner 12.3.0 (a8a019e0)
on gitlab-runner2 QNyj_HGG
Using Docker executor with image nexus.XXX.com/YYY/ZZZ-engines ...
Authenticating with credentials from /root/.docker/config.json
Pulling docker image nexus.XXX.com/YYY/ZZZ-engines ...
ERROR: Job failed: Error response from daemon: manifest for
nexus.XXX.com/YYY/ZZZ-engines:latest not found: manifest unknown: manifest unknown (executor_docker.go:188:0s)
What could be the reason behind that?
I had the same problem, I solved it by rebuilding and republishing the docker image that the GitLab CI file was referencing and then re-run the pipeline again and it worked.
There is no latest tag for that specific docker image. Most likely you're building using a specific tag, e.g v1.0:
docker build -t nexus.XXX.com/YYY/ZZZ-engines:v1.0 .
then using that image without a tag in your .gitlab-ci.yml:
image: nexus.XXX.com/YYY/ZZZ-engines
# OR
build-job:
stage: build
image: nexus.XXX.com/YYY/ZZZ-engines
...
To fix, either specify a tag in you ci file, or tag the image with latest when building:
docker build -t nexus.XXX.com/YYY/ZZZ-engines:v1.0 -t nexus.XXX.com/YYY/ZZZ-engines:latest .
The gitlab docker template has a nice example of how to automatically tag a build as latest on the default branch: https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Docker.gitlab-ci.yml

docker image in gitlab CI used for create docker image

I want to build docker with "ready to run" application in docker CI, so to do that I have created in .gitlab-ci.yml this code:
rebuild base docker:
stage: prepear
image: docker
script:
- docker build -t base_django environment
I want to use the official docker image to do it (image: docker), of course in directory environment I have placed Dockerfile. Unfortunately job faild on:
Running with gitlab-runner 11.8.0 (4745a6f3)
on docker-auto-scale 72989761
Using Docker executor with image docker ...
Pulling docker image docker ...
Using docker image sha256:639de9917ae1f2e4a586893c9a6ea3f21fd774bc4037184ecac35f3153a293b5 for docker ...
Running on runner-72989761-project-9841176-concurrent-0 via runner-72989761-srm-1552402128-c63119b1...
Cloning repository...
Cloning into '/builds/*****/*****'...
Checking out a804a12f as master...
Skipping Git submodules setup
$ docker build -t base_django environment
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
ERROR: Job failed: exit code 1
You need a specific configuration to run docker in docker with Gitlab CI. You can find more information right here : https://docs.gitlab.com/ee/ci/docker/using_docker_build.html

Jenkins docker setup

I am using Jenkins to make build of project, but now my client wants to make builds inside of a Docker image. i have installed docker on server and its running on 172.0.0.1:PORT. I have installed Docker plugin and assigned this TCP URL to Docker URL. I have also created an image with the name jenkins-1
In configure project I use Build environment Build with Docker Container and provide image name. and then in Build in put Execute Shell and then Build it
But it gives the Error:
Pull Docker image jenkins-1 from repository ...`
$ docker pull jenkins-1`
Failed to pull Docker image jenkins-1`
FATAL: Failed to pull Docker image jenkins-1`
java.io.IOException: Failed to pull Docker image jenkins-1``
at com.cloudbees.jenkins.plugins.docker_build_env.PullDockerImageSelector.prepare DockerImage(PullDockerImageSelector.java:34)`
at com.cloudbees.jenkins.plugins.docker_build_env.DockerBuildWrapper.setUp(DockerB`uildWrapper.java:169)`
at hudson.model.Build$BuildExecution.doRun(Build.java:156)`
at `hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:534)`
at hudson.model.Run.execute(Run.java:1720)`
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)`
at hudson.model.ResourceController.execute(ResourceController.java:98)`
at hudson.model.Executor.run(Executor.java:404)`
Finished: FAILURE`
I just have run into the same issue. There is a 'Verbose' check-box in the configuration of build environment after selecting 'Advanced...' link to expand on the error details:
CloudBees plug-in Verbose option
In my case I ran out of space downloading the build Docker images. Expanding ec2 volume has resolved the issue.
But there is an ongoing trouble with space as docker does not auto cleans images and I have ended up adding a manual cleanup step into the build:
docker volume ls -qf dangling=true | xargs -r docker volume rm
Complete build script:
https://bitbucket.org/vk-smith/dotnetcore-api/src/master/ci-build.sh?fileviewer=file-view-default

build docker image with dockerfile by jenkins

I've been blocked since yesterday and need some help. I tried to use both jenkins docker-plugin and docker-plugin-step to build docker image from a dockerfile.
However, when I try to run the jenkins job, it gives me the following exception:
Docker Build
Docker Build : build with tag jdubois/jhipster-docker:Gateway_Jenkins_V1 at path /home/javateam/DockerfileGateway
ERROR: Build step failed with exception
java.lang.NullPointerException: config was not specified
at shaded.com.google.common.base.Preconditions.checkNotNull(Preconditions.java:226)
at com.github.dockerjava.core.DockerClientImpl.<init>(DockerClientImpl.java:36)
at com.github.dockerjava.core.DockerClientImpl.getInstance(DockerClientImpl.java:52)
at com.github.dockerjava.core.DockerClientBuilder.getInstance(DockerClientBuilder.java:29)
at com.nirima.jenkins.plugins.docker.builder.DockerBuilderPublisher$Run$1.invoke(DockerBuilderPublisher.java:144)
at com.nirima.jenkins.plugins.docker.builder.DockerBuilderPublisher$Run$1.invoke(DockerBuilderPublisher.java:139)
at hudson.FilePath.act(FilePath.java:991)
at hudson.FilePath.act(FilePath.java:969)
at com.nirima.jenkins.plugins.docker.builder.DockerBuilderPublisher$Run.buildImage(DockerBuilderPublisher.java:139)
at com.nirima.jenkins.plugins.docker.builder.DockerBuilderPublisher$Run.run(DockerBuilderPublisher.java:89)
at com.nirima.jenkins.plugins.docker.builder.DockerBuilderPublisher.perform(DockerBuilderPublisher.java:180)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:779)
at hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.build(MavenModuleSetBuild.java:915)
at hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.doRun(MavenModuleSetBuild.java:866)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:537)
at hudson.model.Run.execute(Run.java:1744)
at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:531)
at hudson.model.ResourceController.execute(ResourceController.java:98)
at hudson.model.Executor.run(Executor.java:374)
Build step 'Build / Publish Docker Containers' marked build as failure
Finished: FAILURE
The following is the dockerfile content:
#Basic images for Gateway MS
FROM jdubois/jhipster-docker:Gateway_Jenkins_V1
#Fetch last Gateway MS version from gitlab and run it
RUN cd /home/jhipster/DockerJenkinsGateway && \
git pull origin master
# expose the working directory, the Tomcat port, the BrowserSync ports, the SSHD port, and run SSHD
VOLUME ["/jhipster"]
EXPOSE 8080 3000 3001 22
CMD /usr/sbin/sshd -D
What am doing wrong??
Another option is to use the shell provided by Jenkins as a build step, and just build the Docker image using the command-line arguments you would normally use in that shell script.
That's what we do on our build server and it gives us fine grained control over things like versioning and which image/tag to push to Dockerhub.
If you are using Jenkins 2.0 or above then Jenkins give you an option to build pipeline as the code and you can easily integrate docker and its repositories.
Go to --> new item --> select multi branch pipeline option and you will see the option to connect to docker via Jenkins.
Let me know in case of more details.

Resources