Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ubuntu Docker无法解析';deb.debian.org';_Ubuntu_Docker_Debian - Fatal编程技术网

Ubuntu Docker无法解析';deb.debian.org';

Ubuntu Docker无法解析';deb.debian.org';,ubuntu,docker,debian,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

我试图在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
我试图用命令
sudocker 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.org
dig deb.debian.org

如果无法从主机解析,请将
名称服务器8.8.8.8
添加到
/etc/resolv.conf
文件中,然后重试。 Docker从
/etc/resolv.conf
文件复制名称服务器

也可以通过创建文件
/etc/docker/daemon.json

{
    "dns": ["8.8.8.8"]
}
然后重新启动docker服务:

$ service docker restart

看起来您的docker无法正确解析主机。要检查docker是否能够解析DNS,请执行以下命令。在某些环境中,网络管理员可能会阻止8.8.8.8。如果8.8.8.8被阻止,请使用您的本地DNS IP

sudo docker run busybox nslookup google.com

sudo docker run --dns 8.8.8.8 busybox nslookup google.com
如果第一个命令不工作,第二个命令工作正常,则表明这是DNS解析问题。现在编辑/etc/docker/daemon.json并在上面的命令中添加为您工作的DNS服务器IP

{
    "dns": ["8.8.8.8"]
}
使用以下命令重新启动docker服务,使更改生效

service docker restart
执行以下命令以查看docker现在可以解析DNS名称

sudo docker run busybox nslookup google.com

我在套接字上遇到权限错误,导致DNS无法工作<代码>sudo apt get purge--本文中的自动删除apparmor最终为我解决了这个问题。Ubuntu-buster。

这并没有解决根本问题,但我成功地将
--network=host
添加到docker build命令中,例如
sudo docker build--network=host-t ics image。
。在我的例子中,
/etc/resolve.conf
中的所有内容都是正确的,但是docker使用正确的ip表时出现了一个问题,这是一个快速的解决方法。同样,这不是一个解决方案,但可能有助于调试该问题。

您可以添加与windows powershell等效的命令吗?这100%解决了我的问题。谢谢你!非常好,谢谢!我需要在添加到/etc/resolve.conf后重新启动守护程序,但不需要daemon.json编辑。