我在RHEL 7上使用docker版本1.10.1并在使用Dockerfile下面时获取npm install错误.错误:getaddrinfo ENOTFOUND registry.npmjs.org registry.npmjs.org:443.与ubuntu 14.04上的docker 1.91相同的工作.当我得到bash并在容器上安装inetutils-ping时,我注意到我无法ping任何地方
root@9deb4b274c1e:/home/nodexp#ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8): 56 data bytes
^C--- 8.8.8.8 ping statistics ---
4 packets transmitted, 0 packets received, 100% packet loss
Run Code Online (Sandbox Code Playgroud)
这是为什么 ?当然我可以从RHEL ping
Dockerfile
FROM node:argon
# Create user nodexp in group nodexp
RUN groupadd -r nodexp \
&& useradd -m -r -g nodexp nodexp
WORKDIR /home/nodexp
# Install app dependencies
COPY package.json /home/nodexp
RUN npm install
# Bundle app source
COPY . /home/nodexp
EXPOSE 3000
CMD [ "npm", "start" …Run Code Online (Sandbox Code Playgroud) 我从 Strato 租了一台 VPS Linux VC4-8 服务器,想在上面部署一些 Docker 容器。不幸的是,部署的容器无法访问互联网或无法解析 DNS。因此,我无法像RUN apk update
构建过程中那样运行命令。
我已经尝试了各种解决方案,但不幸的是没有成功。以下是我已经阅读和尝试过的一些主题:
https://superuser.com/questions/1130898/no-internet-connection-inside-docker-containers
https://forums.docker.com/t/no-internet-access-in-the-docker-containers/108223
https://askubuntu.com/questions/1445229/no-network-access-from-within-docker-container
以下是我的问题的示例,从完全干净的服务器(Ubuntu 22.04)开始:
ping 8.8.8.8或ping google.com完美运行(在主机上)
使用官方说明安装 Docker (使用 apt 存储库安装)
运行docker pull alpine并docker run --rm -it alpine:latest
连接到 alpine 容器
PING 8.8.8.8 (8.8.8.8): 56 data bytes
^C
--- 8.8.8.8 ping statistics ---
30 packets transmitted, 0 packets received, 100% packet loss
Run Code Online (Sandbox Code Playgroud)
/ # ping google.com
ping: bad address 'google.com'
Run Code Online (Sandbox Code Playgroud)
我还在另一台服务器(来自 Hetzner)上尝试了这些步骤,一切正常。 …
我在堆栈和超级用户上检查了很多类似的问题,但找不到我的确切案例,所以我决定问这个。
我的问题是我的容器仅在构建过程中无法访问互联网。意味着如果我从 Dockerfile 中注释掉任何需要互联网的命令并将执行命令设置为 tail -f /dev/null 然后转到容器 shell,那么我就可以访问互联网。
这是我的失败设置:
我的 docker-compose.yml:
version: '3.7'
services:
admin-panel:
network_mode: host
container_name: react-admin
build:
context: Admin-Panel
volumes:
- ./Admin-Panel:/app
- /app/node_modules
ports:
- '5000:5000'
stdin_open: true
tty: true
Run Code Online (Sandbox Code Playgroud)
和 Dockerfile:
FROM node:13.12.0-alpine
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
COPY package.json yarn.lock ./
RUN yarn --pure-lockfile --silent
COPY . ./
RUN yarn build
CMD ["serve" "-s" "build"]
Run Code Online (Sandbox Code Playgroud)
这将失败并输出以下内容:
docker-compose up --build
Building admin-panel
Step 1/9 : FROM node:13.12.0-alpine
---> 483343d6c5f5
Step 2/9 : WORKDIR /app …Run Code Online (Sandbox Code Playgroud) 我无法在任何 Docker 容器内执行任何需要互联网连接的命令。
作品:
docker run ubuntu /bin/echo 'Hello world'
Run Code Online (Sandbox Code Playgroud)
不起作用:
docker run ubuntu apt-get update
Err:1 http://archive.ubuntu.com/ubuntu xenial InRelease
Temporary failure resolving 'archive.ubuntu.com'
Err:2 http://archive.ubuntu.com/ubuntu xenial-updates InRelease
Temporary failure resolving 'archive.ubuntu.com'
Err:3 http://archive.ubuntu.com/ubuntu xenial-security InRelease
Temporary failure resolving 'archive.ubuntu.com'
Reading package lists...
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/xenial/InRelease Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/xenial-updates/InRelease Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/xenial-security/InRelease Temporary failure resolving 'archive.ubuntu.com'
Run Code Online (Sandbox Code Playgroud)
pip与和类似ping。
我使用的是 Ubuntu 16.04,没有使用防火墙或企业代理服务器,并尝试重新启动 Docker。不使用 docker-machine 或 …