Proxy settings about `failed to fetch oauth token: Post "https://auth.docker.io/token` issue

Hi guys I’m new to docker and now I’m trying encapsulating a simple node server in container using “node:24-alpine” official image. My problem arises that when build image it prompts error as the following one:

[+] Building 31.4s (3/3) FINISHED                                                                      docker:desktop-linux
 => [internal] load build definition from Dockerfile                                                                   0.0s
 => => transferring dockerfile: 168B                                                                                   0.0s
 => ERROR [internal] load metadata for docker.io/library/node:24-alpine                                               31.4s
 => [auth] library/node:pull token for registry-1.docker.io                                                            0.0s
------
 > [internal] load metadata for docker.io/library/node:24-alpine:
------
Dockerfile:1
--------------------
   1 | >>> FROM node:24-alpine
   2 |     
   3 |     WORKDIR /app
--------------------
ERROR: failed to build: failed to solve: failed to fetch oauth token: Post "https://auth.docker.io/token": dial tcp 199.59.148.97:443: i/o timeout

I’m in China where docker domain is banned so I must use proxy. I have configured http/https proxy in Docker-Desktop dashboard and I confirm that the proxy itself works properly, able to access “auth.docker.io/token” by curl with proxy. And the “Search” in Docker-Desktop works properly through proxy.

What makes the situation interesting is, when I enable proxy’s TUN mode (in which every connection goes through proxy transparently), the build procedure finishes with no errors:

[+] Building 20.3s (10/10) FINISHED                                                                    docker:desktop-linux
 => [internal] load build definition from Dockerfile                                                                   0.0s
 => => transferring dockerfile: 168B                                                                                   0.0s
 => [internal] load metadata for docker.io/library/node:24-alpine                                                      3.8s
 => [internal] load .dockerignore                                                                                      0.0s
 => => transferring context: 2B                                                                                        0.0s
 => [1/5] FROM docker.io/library/node:24-alpine@sha256:820e86612c21d0636580206d802a726f2595366e1b867e564cbc652024151e  7.1s
 => => resolve docker.io/library/node:24-alpine@sha256:820e86612c21d0636580206d802a726f2595366e1b867e564cbc652024151e  0.0s
 => => sha256:708abf78a0cfbb78a8ea4eb94e1aebd3ccde74853d1c2889836b62cb1fbfe488 1.72kB / 1.72kB                         0.0s
 => => sha256:fd1e4dac3ed51922603be2bb34c969838453c95c28bbe741700cdc4de96cb411 6.44kB / 6.44kB                         0.0s
 => => sha256:6e174226ea690ced550e5641249a412cdbefd2d09871f3e64ab52137a54ba606 4.13MB / 4.13MB                         2.2s
 => => sha256:1f8203fdb371d554c87f6582b1039cf0e1645b672b0ecc4530fe1d5e643959c0 52.23MB / 52.23MB                       6.2s
 => => sha256:1f6c1379cbe55d90ccef7aa2187b247bbc74f5293105d06d544f9eef6ce111be 1.26MB / 1.26MB                         3.5s
 => => sha256:820e86612c21d0636580206d802a726f2595366e1b867e564cbc652024151e8a 3.87kB / 3.87kB                         0.0s
 => => extracting sha256:6e174226ea690ced550e5641249a412cdbefd2d09871f3e64ab52137a54ba606                              0.1s
 => => sha256:e0ca2d5f38d6b0eb9c8e60a8861af9eb6d3977b5713cd7e434a5981451f6c59a 447B / 447B                             3.9s
 => => extracting sha256:1f8203fdb371d554c87f6582b1039cf0e1645b672b0ecc4530fe1d5e643959c0                              0.7s
 => => extracting sha256:1f6c1379cbe55d90ccef7aa2187b247bbc74f5293105d06d544f9eef6ce111be                              0.0s
 => => extracting sha256:e0ca2d5f38d6b0eb9c8e60a8861af9eb6d3977b5713cd7e434a5981451f6c59a                              0.0s
 => [internal] load build context                                                                                      0.0s
 => => transferring context: 32.04kB                                                                                   0.0s
 => [2/5] WORKDIR /app                                                                                                 0.1s
 => [3/5] COPY package*.json ./                                                                                        0.0s
 => [4/5] COPY server.js ./                                                                                            0.0s
 => [5/5] RUN npm install                                                                                              9.1s
 => exporting to image                                                                                                 0.1s
 => => exporting layers                                                                                                0.1s
 => => writing image sha256:250a32e0f7b46e5cd8c0d4df9cbcf7f0b85b04052590c1ed4a932de07e8b4d96                           0.0s
 => => naming to docker.io/library/myresume-back-docker                                                                0.0s

Given that docker indeed uses the proxy (otherwise Docker-Desktop wouldn’t show any search outcomes; and when I set a invalid proxy ip:port then run “docker build”, it directly prompts “connect: connection refused”, which further confirms docker is using proxy), maybe at the stage of

fetch oauth token: Post "https://auth.docker.io/token"

it doesn’t use proxy?
How could I fix it? Otherwise I could only enable TUN mode everytime I build images…