說來奇幻(對本菜來說, 經常遇到堪稱奇幻的問題)
之前在docker里面各種安裝都沒問題, 也不知道什么引起的, 昨天晚上調試的時候卸載了一個包的版本,然后就安不上了.
宿主機安裝依然各種流暢,唯獨docker容器不行.
網上找了許多方法, 最后在 /etc/resolv.conf 文件內添加如下的代碼解決了:
nameserver 8.8.8.8
https://blog.csdn.net/qq_17351077/article/details/77498173
上面的博客提到了這個方法,但是不明白什么原因, 所以就沒試, 然后在
上又找到了同樣的方案,這次這哥們給了點說明: Docker沒有使用正確的DNS服務器。將谷歌的DNS服務器地址 添加到那個配置文件
Your problem comes from the fact that Docker is not using the proper DNS server. You can fix it in three different ways :
1. Adding Google DNS to your local config
Modifying /etc/resolv.conf and adding the following lines at the end
# Google IPv4 nameservers nameserver 8.8.8.8 nameserver 8.8.4.4
If you want to add other DNS servers, have a look here.
However this change won't be permanent (see this thread). To make it permanent : $ sudo nano /etc/dhcp/dhclient.conf
Uncomment and edit the line with prepend domain-name-server : prepend domain-name-servers 8.8.8.8, 8.8.4.4;
Restart dhclient : $ sudo dhclient
.
2. Modifying Docker config
Systems that run Ubuntu or an Ubuntu derivative on the desktop typically use 127.0.0.1 as the default nameserver in /etc/resolv.conf file.
To specify a DNS server for use by Docker :
1. Log into Ubuntu as a user with sudo privileges.
2. Open the /etc/default/docker file for editing :
$ sudo nano /etc/default/docker
3. Add the following setting for Docker.
DOCKER_OPTS="--dns 8.8.8.8"
4. Save and close the file.
5. Restart the Docker daemon :
$ sudo systemctl restart docker
3. Using a parameter when you run Docker
When you run docker, simply add the following parameter : --dns 8.8.8.8
我是用的第一個方法, 雖然解決了, 但是為什么之前都沒出現這個問題呢?
我服務器默認的是阿里雲的DNS服務器地址, 查看了下我的電腦虛擬機的,用的是虛擬的局域網IP地址,
docker會繼承宿主機的DNS服務器地址,難不成是阿里雲的DNS服務器的問題?但是我宿主機沒事