Docker build: failed to fetch oauth token for openjdk?

Viewed 32057

I'm having trouble understanding this error when trying to build a project in Docker:

> [internal] load metadata for docker.io/library/openjdk:11:
------
failed to solve with frontend dockerfile.v0: failed to create LLB definition: failed to authorize: rpc error: code = Unknown desc = failed to fetch oauth token: unexpected status: 401 Unauthorized'

What does this error mean exactly? Am I missing permissions?

For reference, this is what my Dockerfile looks like:

### base jdk image ###
FROM openjdk:11 as setup
ENV USER sc_user
ENV HOME /home/$USER
ENV REPO $HOME/sc
RUN useradd -u 9999 $USER
COPY --chown=$USER build.gradle gradlew $REPO/
COPY --chown=$USER gradle $REPO/gradle
USER $USER
WORKDIR $REPO
RUN ./gradlew

FROM setup as tdd
ENTRYPOINT ["./gradlew", "-t", "test"]

FROM setup as debug-tdd
ENTRYPOINT ["./gradlew", "-t", "test", "-PjvmArgs=-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005"]

### build jar ###
FROM setup as build
COPY --chown=$USER src $REPO/src
RUN ./gradlew clean test build generatePomFileForMavenJavaPublication
9 Answers

It looks like you have buildkit enabled in your docker configuration. Buildkit is not stable yet and can cause these type of problems. Please try it again with buildkit disabled.

In Linux, using environment variables:

export DOCKER_BUILDKIT=0
export COMPOSE_DOCKER_CLI_BUILD=0

In Windows and macOS, start the Docker Desktop application, go to Settings, select Docker Engine and look for the existing entry:

"buildkit": true

Change this entry to disable buildkit:

"buildkit": false

Then click on Apply & Restart and try it again.

I have also faced this problem after giving the update to new version on my mac. However I have solved the problem after login from terminal.

The commands were:

docker login

After that I have provided the username and password of docker. The problem was fixed.

If you are facing this issue after the subscription changes to docker on August 31st 2021, then it means you need to sign in to docker hub to perform the operations.

Either use docker login from the docker desktop app or use the docker login command from terminal.

If you have not created a docker account before then you can sign up for a personal (free) plan here - https://hub.docker.com/ or use the docker account which your organisation has given you (if you have one).

Changes to the subscription was mentioned here - https://docs.docker.com/subscription/

Using Docker Desktop on *MAC I had to logout and log back in and it worked.

My case:

Using Docker on Windows 10 with Linux WSL2.

The image was for ubuntu:focal.

I had to go to the Troubleshoot section of the docker desktop and use the "Clean / Purge data" option. I previously had tried the "Reset to factory defaults" which gave me an extra line in the error but didn't fix it. So maybe both are needed.

I then restarted Docker and 'VoilĂ '

first, log out if you are logged in and login again: $ docker logout $ docker login provide your credentials.

If you are working in some kind of docker artifactory or inside the organization $ docker login #link_of_the_artifactory_here

My case:

Using Docker on Windows 10 with Linux WSL2.

I just did docker logout and it worked. I remember sometime back I had done docker login.Hence even for public images docker was forcing authentication. The only way out was to either login back or do docker logout. I did docker logout and it worked.

For Windows, You need to login first on Docker Desktop then only it will work.

For me on Windows, simply restart the docker it will work.

Related