While building the docker images for Sitecore JSS with Next.js you may encounter an error like Could not resolve host: nodejs.org or any other domain so this means public host is not reachable and for resolving this try configuring the docker daemon to use a default dns server by configuring daemon.json in windows.
The default google dns servers is 8.8.8.8 so you can configure this in the C:\ProgramData\Docker\config\daemon.json as following and restart the docker desktop.
{
"dns":
[
"8.8.8.8"
]
}
But if you will directly edit the daemon.json then this entry will be removed on docker desktop restart. So better you configure this from docker desktop application under Preferences -> Daemon ->Advanced or alternatively do in the following:
Restart the docker desktop and try again.