环境
我有一个失败的cerbot (让我们加密客户端)在坞容器中。看起来,acme-v02.api.letsencrypt.org不是来自容器的可解析,而是来自主机的可解析(最可能的原因)。我习惯于容器从主机的DNS参数继承,但是,在AWS EC2实例中,似乎有一些子实用程序
DNS手动设置
[ec2-user@ip-172-31-32-243 ~]$ cat /etc/resolv.conf
# Generated by NetworkManager
search eu-west-2.compute.internal
nameserver 172.31.0.2基于此和AWS控制台中的一些元素,我尝试手动添加这些地址。
docker run --dns 172.31.0.2 --dns 172.65.32.248(我可能找不到合适的DNS)
不雅的修补
使用主机的网络解决了这个问题
docker run --network="host"但我只是不太明白为什么。是--network="host"中使用的网络接口问题吗?以下是可供选择的:
[ec2-user@ip-172-31-32-243 ~]$ ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 9001 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
link/ether 0a:d2:81:33:16:f2 brd ff:ff:ff:ff:ff:ff
3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default
link/ether 02:42:9c:c8:d4:ba brd ff:ff:ff:ff:ff:ff
8: br-d15fdfe7243b: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default
link/ether 02:42:e8:56:81:bf brd ff:ff:ff:ff:ff:ff会不会是因为--network="host"诱导使用eth0而不是docker0?如何从acme-v02.api.letsencrypt.org解析docker0
详细误差
An unexpected error occurred:
Traceback (most recent call last):
File "/usr/lib/python3.8/site-packages/urllib3/connection.py", line 156, in _new_conn
conn = connection.create_connection(
File "/usr/lib/python3.8/site-packages/urllib3/util/connection.py", line 61, in create_connection
for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
File "/usr/lib/python3.8/socket.py", line 918, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -3] Try again
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.8/site-packages/urllib3/connectionpool.py", line 665, in urlopen
httplib_response = self._make_request(
File "/usr/lib/python3.8/site-packages/urllib3/connectionpool.py", line 376, in _make_request
self._validate_conn(conn)
File "/usr/lib/python3.8/site-packages/urllib3/connectionpool.py", line 994, in _validate_conn
conn.connect()
File "/usr/lib/python3.8/site-packages/urllib3/connection.py", line 334, in connect
conn = self._new_conn()
File "/usr/lib/python3.8/site-packages/urllib3/connection.py", line 168, in _new_conn
raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.VerifiedHTTPSConnection object at 0x7f55dcc4a130>: Failed to establish a new connection: [Errno -3] Try again
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.8/site-packages/requests/adapters.py", line 439, in send
resp = conn.urlopen(
File "/usr/lib/python3.8/site-packages/urllib3/connectionpool.py", line 719, in urlopen
retries = retries.increment(
File "/usr/lib/python3.8/site-packages/urllib3/util/retry.py", line 436, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='acme-v02.api.letsencrypt.org', port=443): Max retries exceeded with url: /directory (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f55dcc4a130>: Failed to establish a new connection: [Errno -3] Try again'))
During handling of the above exception, another exception occurred:
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='acme-v02.api.letsencrypt.org', port=443): Max retries exceeded with url: /directory (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f55dcc4a130>: Failed to establish a new connection: [Errno -3] Try again'))
Please see the logfiles in /var/log/letsencrypt for more details.发布于 2020-07-20 03:03:42
看来码头内部的DNS解析没有正常工作。
对于linux系统,DNS解析使用/etc/resolv.conf文件进行,检查容器内的这个文件,如果它有无效的DNS,那么容器将无法解析主机名。
Docker使用/etc/docker/daemon.json文件中的属性集(在主机上)在容器中填充/etc/resolv.conf中的条目。
在主机中的/etc/docker/daemon.json文件中更新此属性的值:
{
"dns": ["8.8.8.8"]
}注意:此更改要求重新启动码头才能生效,并且必须再次删除和创建现有容器。
重新启动码头工人:
sudo systemctl restart docker移除容器:
sudo docker stop <container-name/id>
sudo docker rm <container-name/id>您可以添加多个DNS服务器ip地址,使用逗号检查这里分隔每个DNS服务器ip地址,以获得DNS服务器ip地址列表。
干杯!!
https://stackoverflow.com/questions/62968807
复制相似问题