'unauthorized: authentication required error while creating docker nodejs image

I am new to docker and trying to build docker image for my nodejs project.

This is my docker file

FROM node:10
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 8443
CMD ["node", "index.js"]

Command used to build the image

docker build -r test-project .

It is giving unauthorized: authentication required after few minutes

Step 1/7 : FROM node:10
10: Pulling from library/node
76b8ef87096f: Extracting [====================>                              ]  18.81MB/45.38MB
2e2bafe8a0f4: Download complete
b53ce1fd2746: Download complete
84a8c1bd5887: Downloading [==============================>                    ]  30.38MB/49.79MB
7a803dc0b40f: Downloading [========>                                          ]  34.34MB/214.3MB
b800e94e7303: Downloading
0da9fbf60d48: Waiting
04dccde934cf: Waiting
73269890f6fd: Waiting
**unauthorized: authentication required**

I have done authentication before starting build using

docker login -u <username>

Please help with authentication error while building docker image.



Solution 1:[1]

Couple of resolutions -

  1. Try a docker logout. It's possible your authentication with Docker Hub has expired, and your token is being sent along with the pull request, even though these images are public and the token is not needed.
  2. Check for updates and update docker
  3. Logout and login again. (If you are working on windows verify with "docker login")
  4. Check the host clock. It should be properly set to the current time
  5. If docker is behind proxy, try commenting proxy and do sudo systemctl daemon-reload and sudo systemctl restart docker
  6. After you do all the above steps, please try docker pull hello-world. Check if that works
  7. On windows you need to make sure that -

You've shared your drive You've added COMPOSE_CONVERT_WINDOWS_PATHS with value of 1 on you system variables. Try logging out then in from your terminal (When doing it on Docker for Windows - sometimes the issue persists).

  1. Check your network connection. Can be a VPN issue.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dharman