dockerdockerfile

Docker build: failed to fetch oauth token for openjdk?


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

Solution

  • 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.