我正在尝试使用docker-compose在node:alpine图像上构建一个React应用。但是,当时间到了时,npm install
它不会出现以下错误:
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
是我通过vpn访问的注册表的名称。
myCustomRegistry
。我首先认为这可能是因为docker-compose dns无法识别myCustomRegistry
。我可能做错了,这仍然是一个可能的假设。# 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
提前致谢
最后,我决定使用一种解决方法。对于处理相同问题的任何人,这都将局部解决您的问题。请确保您正在使用的所有远程服务器也以这种方式配置。
据我了解,当前无法在使用docker-compose的构建中使用自定义DNS,它仅在运行时使用。因此,要传递自定义DNS,您必须使用替代方法并将其添加到整个全局配置中。
转到/etc/docker
并daemon.json
添加以下内容来编辑或创建JSON文件:
{
"dns": ["<your custom remote dns address here>", "8.8.8.8"]
}
重新启动docker,并使用您的VPN,应该很好:)
请注意,这是一个hack /解决方法,绝不是每个人的好习惯。它的作用域不够好:影响了整个docker作用域,而不仅仅是您的应用程序之一。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句