docker build giving unauthorized: authentication required - docker

My docker version is
Docker version 1.12.2-cs2-ws-beta, build 050b611
I am trying to build the image using command
docker build -t iis-dockerfile .
The DockerFile content is
FROM microsoft/iss
RUN echo "Hello World - Dockerfile" > C:\inetpub\wwwroot\index.html
config.json is
{
"auths": {
"https://index.docker.io/v1/": {
"auth": <somekey>
}
}
}
On running docker build, it gives error
Sending build context to Docker daemon 2.048 kB
Step 1/2 : FROM microsoft/iss
unauthorized: authentication required
I have already done docker login. That's how config.json is created. I am new to containers and following the get started tutorial https://blogs.msdn.microsoft.com/allthingscontainer/2016/09/15/windows-containers-getting-started-a-step-by-step-guide/. Any idea how can I work around this.
Also I figured out that docker pull is working for me. While this also required authentication

Just an observation. Make sure your docker file has correct base image name. Are you sure you want FROM microsoft/iss and not FROM microsoft/iis?
When I tried to create new image with correct base image. It seem to work.
Docker docker build -t test-iid .
Sending build context to Docker daemon 344.9 MB
Step 1/2 : FROM microsoft/iis
latest: Pulling from microsoft/iis
3889bb8d808b: Downloading
3430754e4d17: Downloading
7aee39cd34f9: Downloading [> ] 540 kB/122.7 MB
5b8e6b632025: Download complete
e067d71858d2: Download complete

Related

Docker searching for repository when building base image locally

I have a Dockerfile and base image on my machine. I am attempting to build the image using the Dockerfile commands but after Docker loads the base image, it errors out and says it can't reach a machine. Unsure where this definition is.
I issued command,
docker build -t container-name -f Dockerfile .
It sucks in the base image "Sending build context to Docker daemon" up to the full file size of the base image. But then it says:
"Step 1/10 : FROM base-image
Get https://registry-1.docker.io/v2/: dial tcp: lookup registry-1.docker.io on : read udp -> : i/o timeout
Unsure why it's trying to access a registry when I have the definition and base file in that same directory.
I realized I had not loaded the base image using the Docker Load command...
It was not listed in my "docker images" Repository, therefore it was looking elsewhere.
So, if using your own local image, use:
docker load -i <base_image.tar.gz>
Then it will be in your "docker images" list, and now you can perform the command:
docker build -t -f Dockerfile .
where the Dockerfile contains first line:
FROM base_image
...

docker/docker-compose build --pull behavior

I am trying to find how docker build --pull/docker-compose build --pull option works.
I found a link - https://docs.docker.com/compose/reference/build/
All it says is that -
Always attempt to pull a newer version of the image.
But I still have some questions unanswered -
e.g. consider this image - mcr.microsoft.com/dotnet/core/aspnet:3.0-buster-slim
When I use the --pull flag,
Would it pull aspnetcore 3.1 version if available?
Would it pull nightly build if available?
Would it always download the image regardless if the local image and the latest image are same?
What would happen if the machine doesn't have internet connectivity while running docker build --pull?
Would it pull aspnetcore 3.1 version if available?
No, because it wouldn't be tagged :3.0-buster-slim.
Would it pull nightly build if available?
No, because it wouldn't be tagged :3.0-buster-slim.
Would it always download the image regardless if the local image and the latest image are same?
No. It will download an update if the local and remote sha256 hashes differ. If they're the same it won't re-download it. There's no point.
Let's test it with a simple one-line Dockerfile:
FROM alpine:latest
First time:
$ docker build --pull .
...
latest: Pulling from library/alpine
Digest: sha256:72c42ed48c3a2db31b7dafe17d275b634664a708d901ec9fd57b1529280f01fb
Status: Downloaded newer image for alpine:latest
Subsequent builds:
$ docker build --pull .
...
latest: Pulling from library/alpine
Digest: sha256:72c42ed48c3a2db31b7dafe17d275b634664a708d901ec9fd57b1529280f01fb
Status: Image is up to date for alpine:latest
What would happen if the machine doesn't have internet connectivity while running docker build --pull?
The build fails. With networking disabled, --pull fails:
$ docker build --pull .
Sending build context to Docker daemon 2.048kB
Step 1/1 : FROM alpine:latest
Get https://registry-1.docker.io/v2/: dial tcp: lookup registry-1.docker.io on 127.0.0.53:53: server misbehaving
Without --pull it works:
$ docker build .
Sending build context to Docker daemon 2.048kB
Step 1/1 : FROM ubuntu:latest
---> a2a15febcdf3
Successfully built a2a15febcdf3
no
no
it will always check for a new image with the name:tag mcr.microsoft.com/dotnet/core/aspnet:3.0-buster-slim
it should fail with error

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

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/

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

What does HTTP 400 when pulling docker image mean?

I am asking docker to build an ASP.NET 5 beta6 application image for me at Ubuntu 14.04.1 virtual machine:
docker build -t instanceName .
using dockerfile that starts with:
FROM microsoft/aspnet:1.0.0-beta6
It responds with this message:
Sending build context to Docker daemon 124.4 kB
Sending build context to Docker daemon
Step 0 : FROM microsoft/aspnet:1.0.0-beta6
Pulling repository microsoft/aspnet
9424b500cebc: Error pulling image (1.0.0-beta6) from microsoft/aspnet, HTTP code 400
ba249489d0b6: Download complete
19de96c112fc: Download complete
b92a854a78d0: Download complete
63e9265ef57c: Error pulling dependent layers
INFO[0019] Error pulling image (1.0.0-beta6) from microsoft/aspnet, HTTP code 400
It does similar thing when I replace dockerfile definition to just FROM microsoft/aspnet.
What does it mean? If it were 404, I would understand that there is no such image. But "Bad Request"? Can I make the request... better?

Resources