我试图在docker镜像中安装一些软件包,但是apt-get命令似乎不起作用......
当我在基于ubuntu的容器中尝试此操作时:16.04
apt-get update && apt-get install -y openssh-server
我明白了:
Err:1 http://archive.ubuntu.com/ubuntu zesty InRelease
Temporary failure resolving 'archive.ubuntu.com'
Err:2 http://security.ubuntu.com/ubuntu zesty-security InRelease
Temporary failure resolving 'security.ubuntu.com'
Err:3 http://archive.ubuntu.com/ubuntu zesty-updates InRelease
Temporary failure resolving 'archive.ubuntu.com'
Err:4 http://archive.ubuntu.com/ubuntu zesty-backports InRelease
Temporary failure resolving 'archive.ubuntu.com'
Reading package lists... Done
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/zesty/InRelease Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/zesty-updates/InRelease Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/zesty-backports/InRelease Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/zesty-security/InRelease Temporary failure resolving 'security.ubuntu.com'
W: Some index files failed to download. They have been ignored, or old ones used instead.
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package openssh-server
我尝试在像这样的Dockerfile中执行此操作
FROM ubuntu:16.04
RUN apt-get update && apt-get -y install openssh-server
CMD bin/bash
并使用
构建它sudo docker build -t imagetest .
但我得到了这个:
Sending build context to Docker daemon 2.048kB
Step 1/3 : FROM ubuntu:16.04
---> 00fd29ccc6f1
Step 2/3 : RUN apt-get update && apt-get install openssh-server
---> Running in ee011c1239d0
Err:1 http://archive.ubuntu.com/ubuntu xenial InRelease
Temporary failure resolving 'archive.ubuntu.com'
Err:2 http://security.ubuntu.com/ubuntu xenial-security InRelease
Temporary failure resolving 'security.ubuntu.com'
Err:3 http://archive.ubuntu.com/ubuntu xenial-updates InRelease
Temporary failure resolving 'archive.ubuntu.com'
Err:4 http://archive.ubuntu.com/ubuntu xenial-backports 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-backports/InRelease Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/xenial-security/InRelease Temporary failure resolving 'security.ubuntu.com'
W: Some index files failed to download. They have been ignored, or old ones used instead.
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package openssh-server
The command '/bin/sh -c apt-get update && apt-get install openssh-server' returned a non-zero code: 100
我搜索了官方文档和一些论坛,但我找到的答案都没有帮助我,而且老了......
他们中的一些人说重启码头服务,但它对我不起作用..
其他人说使用apt-get update -qq
,但它也不起作用......
所以我来这里直接询问并得到最近的回答。
感谢。
答案 0 :(得分:2)
如果apt-get在VM上正常工作,您可以使用网络主机模式构建容器。
docker build --network=host ...
答案 1 :(得分:0)
我通过使用与apt.conf中相同的代理设置来解决我的Docker的相同问题(可能不是根本原因)。
只需复制一份atp.conf:
cp /etc/apt/apt.conf apt.conf
,然后在执行任何apt调用之前将以下内容添加到docker-file中:
COPY apt.conf /etc/apt/apt.conf
我希望它可以帮助某人。