docker 遇到 Error while fetching server API version

前言

最近更新 Mac 發現不管怎樣 docker 永遠都無法運行,後來發現解決方式,因此紀錄一下。

事發

最近將 Mac 大更新至 Big Sur v 11.0.1,但卻發生 docker 不管怎麼樣都會出現以下錯誤訊息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
Traceback (most recent call last):
File "site-packages/urllib3/connectionpool.py", line 426, in _make_request
File "<string>", line 3, in raise_from
File "site-packages/urllib3/connectionpool.py", line 421, in _make_request
File "http/client.py", line 1344, in getresponse
File "http/client.py", line 306, in begin
File "http/client.py", line 267, in _read_status
File "socket.py", line 589, in readinto
socket.timeout: timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "site-packages/requests/adapters.py", line 449, in send
File "site-packages/urllib3/connectionpool.py", line 727, in urlopen
File "site-packages/urllib3/util/retry.py", line 403, in increment
File "site-packages/urllib3/packages/six.py", line 735, in reraise
File "site-packages/urllib3/connectionpool.py", line 677, in urlopen
File "site-packages/urllib3/connectionpool.py", line 428, in _make_request
File "site-packages/urllib3/connectionpool.py", line 336, in _raise_timeout
urllib3.exceptions.ReadTimeoutError: UnixHTTPConnectionPool(host='localhost', port=None): Read timed out. (read timeout=60)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "site-packages/docker/api/client.py", line 205, in _retrieve_server_version
File "site-packages/docker/api/daemon.py", line 181, in version
File "site-packages/docker/utils/decorators.py", line 46, in inner
File "site-packages/docker/api/client.py", line 228, in _get
File "site-packages/requests/sessions.py", line 543, in get
File "site-packages/requests/sessions.py", line 530, in request
File "site-packages/requests/sessions.py", line 643, in send
File "site-packages/requests/adapters.py", line 529, in send
requests.exceptions.ReadTimeout: UnixHTTPConnectionPool(host='localhost', port=None): Read timed out. (read timeout=60)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "docker-compose", line 3, in <module>
File "compose/cli/main.py", line 67, in main
File "compose/cli/main.py", line 123, in perform_command
File "compose/cli/command.py", line 69, in project_from_options
File "compose/cli/command.py", line 132, in get_project
File "compose/cli/docker_client.py", line 43, in get_client
File "compose/cli/docker_client.py", line 170, in docker_client
File "site-packages/docker/api/client.py", line 188, in __init__
File "site-packages/docker/api/client.py", line 213, in _retrieve_server_version
docker.errors.DockerException: Error while fetching server API version: UnixHTTPConnectionPool(host='localhost', port=None): Read timed out. (read timeout=60)
[40649] Failed to execute script docker-compose

解決方法

後來我嘗試更新過 Docker,目前版本是 v3.0.2

Docker for Mac release notes

其中在這一篇「Docker won’t run on Big Sur」有提到「Hi, this is a breaking change that can be fixed by upgrading your docker version to 2.3.0.4 Docker already pushed an update and upgrading docker fixes the bug of it not lunching on your Apple Big Sur.」,但我這邊已經更新到 v3.0.2 卻還是一直出現 Error while fetching server API version 的狀況,其中也包含我只要輸入 docker 就會卡住等問題。

後來注意到下方其他人討論使用「Go to Docker Troubleshoot -> Clean/purge data -> Reset to Factory defaults.」就可以確實地解決我的問題並重新運行哩~

我想這問題應該是出在我更新版本之後 docker 沒有重新啟動導致,因此 docker 在獲取 API 時才會無法運作。

參考文獻