ubuntu - Docker 无法解析 'deb.debian.org'

标签 ubuntu docker debian

我试图在 Docker 中构建一个容器用于一些实验。这是我的 Dockerfile

FROM debian

RUN mkdir -p /var/run/sshd

RUN apt-get update
RUN apt-get install -y openssh-server

RUN apt-get install -y sudo

RUN echo AddressFamily inet >> /etc/ssh/sshd_config

ARG username=Rivers
ARG userpasswd=perfectXJ2017

RUN useradd -ms /bin/bash $username && (echo $username:$userpasswd | chpasswd)

RUN adduser $username sudo

CMD /usr/sbin/sshd -D

我尝试使用命令 sudo docker build -t ics-image . 构建我的镜像。

但随后我收到了一些错误消息,整个过程停止了。这是错误消息。

Sending build context to Docker daemon  2.048kB
Step 1/11 : FROM debian
 ---> 8626492fecd3
Step 2/11 : RUN mkdir -p /var/run/sshd
 ---> Running in 1e1f2dbbe5ca
Removing intermediate container 1e1f2dbbe5ca
 ---> dd4bec2f81d4
Step 3/11 : RUN apt-get update
 ---> Running in 022301215bfb
Get:1 http://security.debian.org/debian-security stretch/updates InRelease [94.3 kB]
Get:2 http://security.debian.org/debian-security stretch/updates/main amd64 Packages [450 kB]
Err:3 http://deb.debian.org/debian stretch InRelease
  Could not resolve 'deb.debian.org'
Err:4 http://deb.debian.org/debian stretch-updates InRelease
  Could not resolve 'deb.debian.org'
Fetched 544 kB in 20s (26.9 kB/s)
Reading package lists...
W: Failed to fetch http://deb.debian.org/debian/dists/stretch/InRelease  Could not resolve 'deb.debian.org'
W: Failed to fetch http://deb.debian.org/debian/dists/stretch-updates/InRelease  Could not resolve 'deb.debian.org'
W: Some index files failed to download. They have been ignored, or old ones used instead.
Removing intermediate container 022301215bfb
 ---> 054d32710b62
Step 4/11 : RUN apt-get install -y openssh-server
 ---> Running in 802d2fa37b8d
Reading package lists...
Building dependency tree...
Reading state information...
Package openssh-server is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'openssh-server' has no installation candidate
The command '/bin/sh -c apt-get install -y openssh-server' returned a non-zero code: 100

我在 Ubuntu 18.04 上完成了所有这些工作。我不明白为什么会这样以及如何解决这个问题。谁能帮忙?

最佳答案

您应该首先检查您是否能够从运行 docker 的主机解析 deb.debian.org。你可以检查一下 nslookup deb.debian.orgdig deb.debian.org

如果您无法解析 from host 添加 nameserver 8.8.8.8 到您的 /etc/resolv.conf 文件,然后重试。 Docker 从 /etc/resolv.conf 文件复制名称服务器。

或者您可以通过创建文件 /etc/docker/daemon.json 来设置名称服务器

{
    "dns": ["8.8.8.8"]
}

然后重启docker服务:

$ service docker restart

关于ubuntu - Docker 无法解析 'deb.debian.org',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51034120/

相关文章:

ruby-on-rails - Docker:服务器是否在主机 “localhost”(::1)上运行并在端口5432上接受TCP/IP连接?

docker - 在多个ec2节点上设置zookeeper集群时0.0.0.0是什么意思

linux - 文件描述符限制更新失败

ubuntu - 在启动时挂载 AWS EFS 的 Cron 作业 - Ubuntu

java - 您可以在 Ubuntu 18.04.3 "bionic"上使用 GCP 上的 OpenJDK 将 rundeck 直接从 3.0.22 升级到 3.2.1 吗?

php - "Unable to locate package"仅在 docker 镜像内

Docker Postgres 清除所有数据

php - Debian:PHP7 不工作

dependencies - 用于拆分包的不同前/后 inst/rm 维护者脚本和单元文件?

ubuntu - 正常关闭在 Google Cloud VM 上运行的进程的最佳方法