Unable to build the docker image

I am following the tutorial mentioned in the official Docker docs to build a docker image .

I have cloned the repo,installed docker and followed all the instructions .
It then tells to run the following command : docker build -t getting-started .

My build starts but suddenly fails in step 4.Attaching the logs for your reference .

[+] Building 72.0s (12/12) FINISHED
 => [internal] load build definition from Dockerfile                                                        0.1s 
 => => transferring dockerfile: 193B                                                                        0.0s 
 => [internal] load .dockerignore                                                                           0.1s 
 => => transferring context: 2B                                                                             0.0s 
 => resolve image config for docker.io/docker/dockerfile:1                                                  1.3s 
 => CACHED docker-image://docker.io/docker/dockerfile:1@sha256:39b85bbfa7536a5feceb7372a0817649ecb2724562a  0.0s 
 => [internal] load build definition from Dockerfile                                                        0.0s 
 => [internal] load .dockerignore                                                                           0.0s
 => [internal] load metadata for docker.io/library/node:18-alpine                                           1.3s 
 => [internal] load build context                                                                           0.1s 
 => => transferring context: 2.65kB                                                                         0.1s 
 => [1/4] FROM docker.io/library/node:18-alpine@sha256:ca5d399560a9d239cbfa28eec00417f1505e5e108f3ec6938d2  0.0s
 => CACHED [2/4] WORKDIR /app                                                                               0.0s 
 => [3/4] COPY . .                                                                                          0.1s 
 => ERROR [4/4] RUN yarn install --production                                                              67.8s 
------
 > [4/4] RUN yarn install --production:
#12 1.994 yarn install v1.22.19
#12 2.574 [1/4] Resolving packages...
#12 3.959 [2/4] Fetching packages...
#12 9.694 error An unexpected error occurred: "https://registry.yarnpkg.com/express/-/express-4.18.2.tgz: getaddrinfo EAI_AGAIN registry.yarnpkg.com".
#12 9.695 info If you think this is a bug, please open a bug report with the information provided in "/app/yarn-error.log".
#12 9.695 info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
------
executor failed running [/bin/sh -c yarn install --production]: exit code: 1

Help me resolve this.

Hello,
its basically a network error in your Host machine.

you can check if DNS resolution is happening properly or not.

# for Linux check DNS
cat /etc/resolv.conf

if you are running docker behind VPN or proxy make sure it can access

registry.yarnpkg.com

below is output when I tried to reproduce

 => [internal] load build definition from Dockerfile                                                                                                                                                     0.0s
 => => transferring dockerfile: 221B                                                                                                                                                                     0.0s
 => [internal] load .dockerignore                                                                                                                                                                        0.0s
 => => transferring context: 2B                                                                                                                                                                          0.0s
 => resolve image config for docker.io/docker/dockerfile:1                                                                                                                                               1.6s
 => CACHED docker-image://docker.io/docker/dockerfile:1@sha256:39b85bbfa7536a5feceb7372a0817649ecb2724562a38360f4d6a7782a409b14                                                                          0.0s
 => [internal] load build definition from Dockerfile                                                                                                                                                     0.0s
 => [internal] load .dockerignore                                                                                                                                                                        0.0s
 => [internal] load metadata for docker.io/library/node:18-alpine                                                                                                                                        1.9s
 => [internal] load build context                                                                                                                                                                        0.1s
 => => transferring context: 4.60MB                                                                                                                                                                      0.1s
 => [1/4] FROM docker.io/library/node:18-alpine@sha256:ca5d399560a9d239cbfa28eec00417f1505e5e108f3ec6938d230767eaa81f61                                                                                  5.4s
 => => resolve docker.io/library/node:18-alpine@sha256:ca5d399560a9d239cbfa28eec00417f1505e5e108f3ec6938d230767eaa81f61                                                                                  0.0s
 => => sha256:ca5d399560a9d239cbfa28eec00417f1505e5e108f3ec6938d230767eaa81f61 1.43kB / 1.43kB                                                                                                           0.0s
 => => sha256:46f34dda633f5708462f6d6ee7ef829535bd0ee04b82cbe28dcccb5df74b3eb1 1.16kB / 1.16kB                                                                                                           0.0s
 => => sha256:a966e12937d2cdbf1cf501f972673875426566c53820a3fe54c2a15b0ad93639 6.50kB / 6.50kB                                                                                                           0.0s
 => => sha256:762c2470eea4dfd0e37925b903f27172a7b89fd8b11bb8cf61554941c3293636 47.28MB / 47.28MB                                                                                                         4.3s
 => => sha256:fefc7d195eee885e1f309ca2b5eff078b537b766f6bd949f8eb69fe895088821 2.41MB / 2.41MB                                                                                                           1.4s
 => => sha256:06fc22ed341f1d0c400e6972828f8731f3544007cda80ea1d333fe15acf0a28b 448B / 448B                                                                                                               0.6s
 => => extracting sha256:762c2470eea4dfd0e37925b903f27172a7b89fd8b11bb8cf61554941c3293636                                                                                                                0.9s
 => => extracting sha256:fefc7d195eee885e1f309ca2b5eff078b537b766f6bd949f8eb69fe895088821                                                                                                                0.1s
 => => extracting sha256:06fc22ed341f1d0c400e6972828f8731f3544007cda80ea1d333fe15acf0a28b                                                                                                                0.0s
 => [2/4] WORKDIR /app                                                                                                                                                                                   0.1s
 => [3/4] COPY . .                                                                                                                                                                                       0.0s
 => [4/4] RUN yarn install --production                                                                                                                                                                  8.3s
 => exporting to image                                                                                                                                                                                   0.6s
 => => exporting layers                                                                                                                                                                                  0.6s
 => => writing image sha256:ba54325a6008dc50827e5fd5df91ad46c7aa6252847318fe8d4362c26c1dedf1                                                                                                             0.0s
 => => naming to docker.io/library/getting-started
1 Like

Great.Thanks for the solution.

I fixed it by changing my public DNS to point to Google’s DNS .
8.8.8.8 / 4.4.4.4 and now it works perfectly fine.

1 Like