Building docker image fails with failed to fetch anonymous token, TLS handshake timeout

I got a problem while creating a docker image using docker build -t image_name .. When I execute it I get errors:

 => [internal] load build definition from Dockerfile 0.1s => => transferring dockerfile: 32B 0.0s => [internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => ERROR [internal] load metadata for 0.2s
------ > [internal] load metadata for
------
failed to solve with frontend dockerfile.v0: failed to create LLB definition: failed to authorize: rpc error: code = Unknown desc = failed to fetch anonymous token: Get net/http: TLS handshake timeout
4

1 Answer

This recently happened for me when running a build script for earthly/earthly.

OS: Arch Linux 5.14.8-arch1-1

Docker from official repository: Docker version 20.10.8, build 3967b7d28e

Solution (likely a Linux-only solution)

DNS was misconfigured for me. For some reason, docker pull golang:1.16-alpine3.14 worked fine but was failing when running the build script. This answer on r/docker helped.

Adding a DNS nameserver to my /etc/resolv.conf solved this issue for me:

cat /etc/resolve.conf
# Cloudflare
nameserver 1.1.1.1

Other Attempted Solutions

1. Disable Buildkit

From this answer to Docker build: failed to fetch oauth token for openjdk?, this did not solve the issue since I believe buildkit was required for the script I was running:

export DOCKER_BUILDKIT=0
export COMPOSE_DOCKER_CLI_BUILD=0

2. Manually pull image

3. Authenticating with Docker

The error looked like something that might happen when I was unauthenticated with hub.docker.com. After logging in with docker login --username <username> I still receieved the errors.

3

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like