Reputation: 49
I am trying to build a react app on a node:alpine image using docker-compose. But when the time comes to npm install
it doesn't work with the following error:
npm ERR! code ENOTFOUND
npm ERR! errno ENOTFOUND
npm ERR! network request to https://<myCustomRegistry>/packageName failed, reason: getaddrinfo ENOTFOUND <myCustomRegistry>
npm ERR! network This is a problem related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly. See: 'npm help config'
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2020-04-03T15_06_13_130Z-debug.log
myCustomRegistry
is the name of my registry which I'm accessing via a vpn.
myCustomRegistry
. I first thought it might come from the fact that the docker-compose dns could not know myCustomRegistry
. I might have done it wrong this is still a possible hypothesis.# Builds the react app into 3 static files
FROM node:alpine as builder
WORKDIR /app
COPY . .
RUN npm i && npm run build
# Copies those static files and serve them
FROM node:alpine
RUN yarn global add serve
WORKDIR /app
COPY --from=builder /app/build .
EXPOSE 80
CMD ["serve", "-p", "80", "-s", "."]
version: "3.7"
services:
<... other services>
front:
build: ./front
container_name: dobby_front
ports:
- "8080:80"
volumes:
- './front:/app'
- '/app/node_modules'
dns:
- 10.128.103.16
- 172.21.103.5
registry=https://<myCustomRegistry>
save-exact=true
Thanks in advance
Upvotes: 2
Views: 2971
Reputation: 736
I had tried using all variations of DNS servers in the daemon.json file, but it would not find the registry.
I tried using the IP address of the registry instead of the fully qualified domain name (url):
npm i <package-name> --registry http://<ip-address>
I then modified my .npmrc to use the IP instead of the URL and npm i
worked.
registry=http://<ip-address>
I did not have to change DNS entries.
EDIT
I realised that the URL I provided did not have the domain name or TLD (e.g. .[company-name].com). Upon adding this to original URL and also modifying DNS entry as mentioned in the answer it worked:
from
registry=http://<machine-name>
to
registry=http://<machine-name>.<company-name>.com
Upvotes: 0
Reputation: 49
In the end I decided to use a workaround. For anyone dealing with the same issue, this will solve you problem LOCALLY. Please make sure any remote servers you're working with are also configured this way.
As I understood, it is not currently possible to use a custom DNS in build using docker-compose, it is only used in run. Therefore, to pass on a custom DNS, you have to use a workaround and add it to the entire global config.
Go to /etc/docker
and edit or create a JSON file daemon.json
adding the following:
{
"dns": ["<your custom remote dns address here>", "8.8.8.8"]
}
The restart docker and, using your VPN this should be good to go:)
Please note that this is a hack/workaround and in no way a good practice for everyone. It's not well scoped: affecting your whole docker scope instead of just the one of your app.
Upvotes: 3