実現したいこと
InsightFaceとFastAPIで顔検出サーバを作ってみた
このサイトの内容と全く同じように、Dockerイメージをビルド、起動したのですが、ビルド段階でエラーが発生してしまいました。
ネットワーク関係のエラーかと思い一日中調べましたが、全く直る気配がなく、質問させていただきました。
発生している問題・エラーメッセージ
PS C:\..中略..\202107-face-detector> docker-compose build ---中略--- => ERROR [10/13] RUN ./src/get_model.py 26.0s ------ > [10/13] RUN ./src/get_model.py: #0 25.56 download_path: /root/.insightface/models/antelopev2 #0 25.56 Downloading /root/.insightface/models/antelopev2.zip from http://storage.insightface.ai/files/models/antelopev2.zip... #0 25.57 Traceback (most recent call last): #0 25.57 File "/usr/local/lib/python3.8/dist-packages/urllib3/connection.py", line 174, in _new_conn #0 25.57 conn = connection.create_connection( #0 25.57 File "/usr/local/lib/python3.8/dist-packages/urllib3/util/connection.py", line 95, in create_connection #0 25.57 raise err #0 25.57 File "/usr/local/lib/python3.8/dist-packages/urllib3/util/connection.py", line 85, in create_connection #0 25.57 sock.connect(sa) #0 25.57 ConnectionRefusedError: [Errno 111] Connection refused #0 25.57 #0 25.57 During handling of the above exception, another exception occurred: #0 25.57 #0 25.57 Traceback (most recent call last): #0 25.57 File "/usr/local/lib/python3.8/dist-packages/urllib3/connectionpool.py", line 703, in urlopen #0 25.57 httplib_response = self._make_request( #0 25.57 File "/usr/local/lib/python3.8/dist-packages/urllib3/connectionpool.py", line 398, in _make_request #0 25.57 conn.request(method, url, **httplib_request_kw) #0 25.57 File "/usr/local/lib/python3.8/dist-packages/urllib3/connection.py", line 239, in request #0 25.57 super(HTTPConnection, self).request(method, url, body=body, headers=headers) #0 25.57 File "/usr/lib/python3.8/http/client.py", line 1256, in request #0 25.57 self._send_request(method, url, body, headers, encode_chunked) #0 25.57 File "/usr/lib/python3.8/http/client.py", line 1302, in _send_request #0 25.57 self.endheaders(body, encode_chunked=encode_chunked) #0 25.57 File "/usr/lib/python3.8/http/client.py", line 1251, in endheaders #0 25.57 self._send_output(message_body, encode_chunked=encode_chunked) #0 25.57 File "/usr/lib/python3.8/http/client.py", line 1011, in _send_output #0 25.57 self.send(msg) #0 25.57 File "/usr/lib/python3.8/http/client.py", line 951, in send #0 25.57 self.connect() #0 25.57 File "/usr/local/lib/python3.8/dist-packages/urllib3/connection.py", line 205, in connect #0 25.57 conn = self._new_conn() #0 25.57 File "/usr/local/lib/python3.8/dist-packages/urllib3/connection.py", line 186, in _new_conn #0 25.57 raise NewConnectionError( #0 25.57 urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7f95d8e43f40>: Failed to establish a new connection: [Errno 111] Connection refused #0 25.57 #0 25.57 During handling of the above exception, another exception occurred: #0 25.57 #0 25.57 Traceback (most recent call last): #0 25.57 File "/usr/local/lib/python3.8/dist-packages/requests/adapters.py", line 489, in send #0 25.57 resp = conn.urlopen( #0 25.57 File "/usr/local/lib/python3.8/dist-packages/urllib3/connectionpool.py", line 787, in urlopen #0 25.57 retries = retries.increment( #0 25.57 File "/usr/local/lib/python3.8/dist-packages/urllib3/util/retry.py", line 592, in increment #0 25.57 raise MaxRetryError(_pool, url, error or ResponseError(cause)) #0 25.57 urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='storage.insightface.ai', port=80): Max retries exceeded with url: /files/models/antelopev2.zip (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f95d8e43f40>: Failed to establish a new connection: [Errno 111] Connection refused')) #0 25.57 #0 25.57 During handling of the above exception, another exception occurred: #0 25.57 #0 25.57 Traceback (most recent call last): #0 25.57 File "./src/get_model.py", line 5, in <module> #0 25.57 insightface.app.FaceAnalysis() #0 25.57 File "/usr/local/lib/python3.8/dist-packages/insightface/app/face_analysis.py", line 28, in __init__ #0 25.57 self.model_dir = ensure_available('models', name, root=root) #0 25.57 File "/usr/local/lib/python3.8/dist-packages/insightface/utils/storage.py", line 28, in ensure_available #0 25.57 return download(sub_dir, name, force=False, root=root) #0 25.57 File "/usr/local/lib/python3.8/dist-packages/insightface/utils/storage.py", line 17, in download #0 25.57 download_file(model_url, #0 25.57 File "/usr/local/lib/python3.8/dist-packages/insightface/utils/download.py", line 71, in download_file #0 25.57 r = requests.get(url, stream=True) #0 25.57 File "/usr/local/lib/python3.8/dist-packages/requests/api.py", line 73, in get #0 25.57 return request("get", url, params=params, **kwargs) #0 25.57 File "/usr/local/lib/python3.8/dist-packages/requests/api.py", line 59, in request #0 25.57 return session.request(method=method, url=url, **kwargs) #0 25.57 File "/usr/local/lib/python3.8/dist-packages/requests/sessions.py", line 587, in request #0 25.57 resp = self.send(prep, **send_kwargs) #0 25.57 File "/usr/local/lib/python3.8/dist-packages/requests/sessions.py", line 701, in send #0 25.57 r = adapter.send(request, **kwargs) #0 25.57 File "/usr/local/lib/python3.8/dist-packages/requests/adapters.py", line 565, in send #0 25.57 raise ConnectionError(e, request=request) #0 25.57 requests.exceptions.ConnectionError: HTTPConnectionPool(host='storage.insightface.ai', port=80): Max retries exceeded with url: /files/models/antelopev2.zip (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f95d8e43f40>: Failed to establish a new connection: [Errno 111] Connection refused')) ------ failed to solve: executor failed running [/bin/sh -c ./src/get_model.py]: exit code: 1
該当のソースコード
コード全文はこちらにあります。
https://github.com/nayutaya/202107-face-detector
python
1#!/usr/bin/env python3 2#質問者注:detector-insightface/src/get_model.py(全文)です。 3 4import insightface 5 6insightface.app.FaceAnalysis()
yaml
1#質問者注:docker-compose.yaml(コメントアウトされたコードを除いたもの)です。 2version: "3" 3services: 4 detector-insightface: 5 build: "detector-insightface" 6 ports: 7 - "8000:8000"
Powershell
1# リポジトリを取得 2git clone https://github.com/nayutaya/202107-face-detector.git 3cd 202107-face-detector 4# タグをチェックアウト 5git checkout 20210727c 6# Dockerイメージをビルドする 7docker-compose build # ← 質問者注:ここでエラーが発生しました。 8# Dockerコンテナをバックグラウンドで起動する 9docker-compose up -d 10 11# (試したあとに)Dockerコンテナを停止する 12docker-compose down
試したこと
さかのぼると
Downloading /root/.insightface/models/antelopev2.zip from http://storage.insightface.ai/files/models/antelopev2.zip... ...中略... ConnectionRefusedError: [Errno 111] Connection refused
となっているので、Dockerのネットワーク関係かと思い、調べて出てきた方法を試しました。
まず、docker-compose.yamlに、
yaml
1#1.下をports:と同じインデントで追加 2network_mode: "host" 3 4#2.下をports:と同じインデントで追加し、 5networks: 6 - host 7# これをファイル末尾に追記。 8networks: 9 host: 10 name: host 11 external: true 12 13#3.下をports:と同じインデントで追加し、 14networks: 15 mynetwork: {} 16# これをファイル末尾に追記。 17networks: 18 mynetwork: 19 name: host 20 external: true
しましたが駄目でした。
また、C:\Users\%userprofile%\.docker\daemon.jsonに
json
1{ "dns": ["8.8.8.8", "8.8.4.4"] }
を追加しましたが駄目でした。
補足情報(FW/ツールのバージョンなど)
元サイトと違い、Docker Desktop for MacではなくDocker Desktop for Windowsを使っています。
回答1件
あなたの回答
tips
プレビュー
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。
また依頼した内容が修正された場合は、修正依頼を取り消すようにしましょう。