gpt4 book ai didi

ubuntu - apt-get 命令在 docker 容器中不起作用

转载 作者:太空宇宙 更新时间:2023-11-03 16:55:55 25 4
gpt4 key购买 nike

我正在尝试在 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

我在官方文档和一些论坛上进行了搜索,但我找到的答案都对我没有帮助,而且都是旧的...

有的说要重启docker服务,但是对我没用..其他人说使用apt-get update -qq,但它也不起作用......

所以我来这里直接问,最近有一个答案。

谢谢。

最佳答案

如果 apt-get 在 VM 上运行良好,您可以使用网络主机模式构建容器。

docker build --network=host ...

关于ubuntu - apt-get 命令在 docker 容器中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48023238/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com