41

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
Kespoco
  • 513
  • 1
  • 4
  • 5

10 Answers10

124

It looks like you have BuildKit enabled in your docker configuration. BuildKit 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.

slhck
  • 36,575
  • 28
  • 148
  • 201
McPringle
  • 1,939
  • 2
  • 16
  • 19
21

I have also faced this problem after updating to a new Docker version on my Mac. However I have solved the problem after logging in again from the terminal.

The command was:

docker login

After that I had to provide username and password for Docker Hub. The problem was fixed.

Note that if you use a custom registry, you have to run docker login <registry> instead.

slhck
  • 36,575
  • 28
  • 148
  • 201
Zakaria
  • 445
  • 4
  • 10
  • 1
    I logged into the docker app and it worked – thisshri Nov 09 '21 at 19:17
  • It didn't work for me. Login successful but still getting 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: 405 Method Not Allowed – Rohit May 16 '22 at 17:23
  • @Rohit you are using on mac? Do you have docker desktop app installed on your machine? – Zakaria May 19 '22 at 07:00
  • Yes to both..... – Rohit May 20 '22 at 08:38
  • @Rohit did you login both in docker desktop app and also from terminal? If yes, there may be another case. Once I had also faced this sort of weird problem due my internet service provider. Idk what is your case? – Zakaria May 22 '22 at 05:13
5

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/

giri-sh
  • 6,934
  • 2
  • 25
  • 50
3

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

Hozeis
  • 1,542
  • 15
  • 36
2

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

Kushal Atreya
  • 183
  • 2
  • 7
1

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à'

Dharman
  • 30,962
  • 25
  • 85
  • 135
Stéphan Champagne
  • 1,259
  • 12
  • 12
1

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.

Rohit Salecha
  • 893
  • 11
  • 9
0

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

Akash Bisariya
  • 3,855
  • 2
  • 30
  • 42
0

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

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 13 '22 at 08:57
0

In my case, this error helped when I tried to make a docker build. But I didn't have openjdk 11. So it helped me to just pull up the openjdk 11 image separately with the command "docker pull thingsboard/openjdk11" from this page"https://hub.docker.com/r/thingsboard/openjdk11 " before doing build.

I note that I didn't have to log in to DockerHub for this. I will also note that this error occurred on Linux Mint.

Сергей
  • 111
  • 4