Docker 图片 Ubuntu 14.04 未连接互联网

Docker images Ubuntu 14.04 not connected internet

我已经在图像 docker 上安装 ubuntu 14:04,使用 docker 文件

在我的 docker 文件中,需要更新和安装 ubuntu

中的应用程序

在docker文件中我填写了如下语法

# get Ubuntu 14.04 images
FROM ubuntu:14.04

# copy file on local to images
COPY erp-enterprise_revisi.tar.gz /home/

# Update repository
RUN apt-get update

# Install mc on Ubuntu 14.04
RUN apt-get install mc

但是这个错误

Sending build context to Docker daemon 1.236 GB
Step 1 : FROM ubuntu:14.04
 ---> e9ae3c220b23
Step 2 : COPY erp-enterprise_revisi.tar.gz /home/
 ---> d94e66b9d23f
Removing intermediate container babeb959ae8e
Step 3 : RUN apt-get update
 ---> Running in ac702e7d10f4
Err http://archive.ubuntu.com trusty InRelease
Err http://archive.ubuntu.com trusty-updates InRelease
Err http://archive.ubuntu.com trusty-security InRelease
Err http://archive.ubuntu.com trusty Release.gpg
  Could not resolve 'archive.ubuntu.com'
Err http://archive.ubuntu.com trusty-updates Release.gpg
  Could not resolve 'archive.ubuntu.com'
Err http://archive.ubuntu.com trusty-security Release.gpg
  Could not resolve 'archive.ubuntu.com'
Reading package lists...
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty/InRelease  
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty-updates/InRelease  
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty-security/InRelease  
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty/Release.gpg  Could not resolve 'archive.ubuntu.com'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty-updates/Release.gpg  Could not resolve 'archive.ubuntu.com'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/trusty-security/Release.gpg  Could not resolve 'archive.ubuntu.com'
W: Some index files failed to download. They have been ignored, or old ones used instead.
 ---> 2093977bf1d3
Removing intermediate container ac702e7d10f4
Step 4 : RUN apt-get install mc
 ---> Running in c38aa81084f4
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package mc
The command '/bin/sh -c apt-get install mc' returned a non-zero code: 100

如何连接到互联网?

刚刚找到这篇文章,所以你应该在安装 mc 之前更改你的存储库,http://slick.pl/kb/linux/installing-midnight-commander-4-8-11-ubuntu-14-04-13-10-13-04-12-04/

在你的 DockerFile 中, 将RUN apt-get install mc替换为RUN apt-get -y install mc,强制回答yes,避免非零码错误

在第 3 层 (RUN apt-get update) 环境中构建时,出现一些网络错误。

当您仅在第 4 层编辑 Dockerfile 时,docker build 使用缓存层,不会为第 1 ~ 3 层再次构建。

您需要使用 -no-cache

重新构建它

所以请尝试以下操作:

$ cat Dockerfile

# get Ubuntu 14.04 images
FROM ubuntu:14.04

# copy file on local to images
#COPY erp-enterprise_revisi.tar.gz /home/

# Update repository
RUN apt-get update

# Install mc on Ubuntu 14.04
RUN apt-get install -y mc         <== Here you need give -y to force the install

$ docker build -no-cache -t test .

参考:Best practices for writing Dockerfiles - Build cache

并不是说它可能适用于这种特殊情况,... ;-)

...但是你会遇到类似的症状(比如容器无法连接到外部世界 - 例如解析 dns 名称,导致这样的事情 "Could not resolve 'archive.ubuntu.com' ") 当 docker 守护程序不是 using/applying 所需的防火墙规则时。 例如使用选项“--iptables=false”或类似选项启动时。

总是值得从容器内部 运行 ping x.x.x.x(例如 google dns 8.8.8.8)以查看是否可以访问。如果它在容器内部不起作用,但在 docker 主机上不起作用,则可能是防火墙设置问题