我正在尝试了解 Prefect docker 代理。为此,我尝试在本地计算机上配置最小设置。我已经设法让 docker 代理连接到本地服务器,看起来它正在运行流程。但是,似乎在流程完成后,代理无法更新服务器上的流程状态,因为它无法连接到服务器后端。
\n这是我的流程:
\nimport prefect\nfrom prefect import task, Flow\nfrom prefect.run_configs import DockerRun\n\n@task\ndef say_hello():\n logger = prefect.context.get("logger")\n logger.info("Hello, docker!")\n\nwith Flow("docker-hello-flow") as flow:\n flow.run_config = DockerRun()\n say_hello()\n\n# Register the flow under the "tutorial" project\nflow.register(project_name="tutorial")\nRun Code Online (Sandbox Code Playgroud)\n我将后端配置为使用本地核心服务器:
\nprefect backend server\nRun Code Online (Sandbox Code Playgroud)\n然后我启动服务器:
\nprefect server start -d\nRun Code Online (Sandbox Code Playgroud)\n我连接到服务器 UIlocalhost:8080并确认它正在运行。
在 UI 中,我创建了项目tutorial。
然后我注册流程:
\n:; python src/hello_docker.py \nFlow URL: http://localhost:8080/default/flow/fea8211e-c243-40c8-a01e-f63ab2afcc77\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 ID: 0a7a6cc4-1e7b-4e71-a900-90dffb4362a9\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 Project: tutorial\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 Labels: ['parami']\nRun Code Online (Sandbox Code Playgroud)\n然后,我确认该流程按预期出现在 UI 中。请注意,我的机器名称是paramilabel parami。
然后,我启动一个指定 label 的本地 docker 代理parami。
:; prefect agent docker start -l parami --log-level DEBUG --show-flow-logs\nRun Code Online (Sandbox Code Playgroud)\n然后我通过 UI 运行流程。流程运行称为enigmatic-axolotl。
docker代理的日志如下:
\n[2021-11-16 22:47:17,076] DEBUG - agent | No ready flow runs found.\n[2021-11-16 22:47:17,076] DEBUG - agent | Sleeping flow run poller for 2.0 seconds...\n[2021-11-16 22:47:18,506] DEBUG - agent | {'status': 'Pulling from prefecthq/prefect', 'id': '0.15.7'}\n[2021-11-16 22:47:18,509] DEBUG - agent | {'status': 'Digest: sha256:e3f6dece4c8d5d7b289cb6e017d3a3b0617d3084df57c2bb96999a2b3c2470f0'}\n[2021-11-16 22:47:18,510] DEBUG - agent | {'status': 'Status: Image is up to date for prefecthq/prefect:0.15.7'}\n[2021-11-16 22:47:18,513] INFO - agent | Successfully pulled image prefecthq/prefect:0.15.7\n[2021-11-16 22:47:18,513] DEBUG - agent | Creating Docker container prefecthq/prefect:0.15.7\n[2021-11-16 22:47:18,578] DEBUG - agent | Starting Docker container with ID 68fea87be44f0332568b2a01e391c5e1822f58f43438df9bb81e228a8edc9625 and name 'enigmatic-axolotl'\n[2021-11-16 22:47:18,976] DEBUG - agent | Docker container 68fea87be44f0332568b2a01e391c5e1822f58f43438df9bb81e228a8edc9625 started\n[2021-11-16 22:47:18,977] INFO - agent | Completed deployment of flow run b1df1042-96a7-4a09-aee0-820468eccf87\n[2021-11-16 22:47:19,076] DEBUG - agent | Querying for ready flow runs...\n[2021-11-16 22:47:19,101] DEBUG - agent | No ready flow runs found.\n[2021-11-16 22:47:19,101] DEBUG - agent | Sleeping flow run poller for 4.0 seconds...\nTraceback (most recent call last):\n File "/usr/local/lib/python3.7/site-packages/urllib3/connection.py", line 175, in _new_conn\n (self._dns_host, self.port), self.timeout, **extra_kw\n File "/usr/local/lib/python3.7/site-packages/urllib3/util/connection.py", line 96, in create_connection\n raise err\n File "/usr/local/lib/python3.7/site-packages/urllib3/util/connection.py", line 86, in create_connection\n sock.connect(sa)\nConnectionRefusedError: [Errno 111] Connection refused\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 706, in urlopen\n chunked=chunked,\n File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 394, in _make_request\n conn.request(method, url, **httplib_request_kw)\n File "/usr/local/lib/python3.7/site-packages/urllib3/connection.py", line 239, in request\n super(HTTPConnection, self).request(method, url, body=body, headers=headers)\n File "/usr/local/lib/python3.7/http/client.py", line 1281, in request\n self._send_request(method, url, body, headers, encode_chunked)\n File "/usr/local/lib/python3.7/http/client.py", line 1327, in _send_request\n self.endheaders(body, encode_chunked=encode_chunked)\n File "/usr/local/lib/python3.7/http/client.py", line 1276, in endheaders\n self._send_output(message_body, encode_chunked=encode_chunked)\n File "/usr/local/lib/python3.7/http/client.py", line 1036, in _send_output\n self.send(msg)\n File "/usr/local/lib/python3.7/http/client.py", line 976, in send\n self.connect()\n File "/usr/local/lib/python3.7/site-packages/urllib3/connection.py", line 205, in connect\n conn = self._new_conn()\n File "/usr/local/lib/python3.7/site-packages/urllib3/connection.py", line 187, in _new_conn\n self, "Failed to establish a new connection: %s" % e\nurllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7f2e7172e690>: Failed to establish a new connection: [Errno 111] Connection refused\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 449, in send\n timeout=timeout\n File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 756, in urlopen\n method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]\n File "/usr/local/lib/python3.7/site-packages/urllib3/util/retry.py", line 574, in increment\n raise MaxRetryError(_pool, url, error or ResponseError(cause))\nurllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='host.docker.internal', port=4200): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f2e7172e690>: Failed to establish a new connection: [Errno 111] Connection refused'))\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File "/usr/local/bin/prefect", line 8, in <module>\n sys.exit(cli())\n File "/usr/local/lib/python3.7/site-packages/click/core.py", line 829, in __call__\n return self.main(*args, **kwargs)\n File "/usr/local/lib/python3.7/site-packages/click/core.py", line 782, in main\n rv = self.invoke(ctx)\n File "/usr/local/lib/python3.7/site-packages/click/core.py", line 1259, in invoke\n return _process_result(sub_ctx.command.invoke(sub_ctx))\n File "/usr/local/lib/python3.7/site-packages/click/core.py", line 1259, in invoke\n return _process_result(sub_ctx.command.invoke(sub_ctx))\n File "/usr/local/lib/python3.7/site-packages/click/core.py", line 1066, in invoke\n return ctx.invoke(self.callback, **ctx.params)\n File "/usr/local/lib/python3.7/site-packages/click/core.py", line 610, in invoke\n return callback(*args, **kwargs)\n File "/usr/local/lib/python3.7/site-packages/prefect/cli/execute.py", line 53, in flow_run\n result = client.graphql(query)\n File "/usr/local/lib/python3.7/site-packages/prefect/client/client.py", line 554, in graphql\n retry_on_api_error=retry_on_api_error,\n File "/usr/local/lib/python3.7/site-packages/prefect/client/client.py", line 458, in post\n retry_on_api_error=retry_on_api_error,\n File "/usr/local/lib/python3.7/site-packages/prefect/client/client.py", line 738, in _request\n session=session, method=method, url=url, params=params, headers=headers\n File "/usr/local/lib/python3.7/site-packages/prefect/client/client.py", line 606, in _send_request\n timeout=prefect.context.config.cloud.request_timeout,\n File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 590, in post\n return self.request('POST', url, data=data, json=json, **kwargs)\n File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 542, in request\n resp = self.send(prep, **send_kwargs)\n File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 655, in send\n r = adapter.send(request, **kwargs)\n File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 516, in send\n raise ConnectionError(e, request=request)\nrequests.exceptions.ConnectionError: HTTPConnectionPool(host='host.docker.internal', port=4200): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f2e7172e690>: Failed to establish a new connection: [Errno 111] Connection refused'))\n[2021-11-16 22:47:23,101] DEBUG - agent | Querying for ready flow runs...\n[2021-11-16 22:47:23,181] DEBUG - agent | No ready flow runs found.\n[2021-11-16 22:47:23,181] DEBUG - agent | Sleeping flow run poller for 8.0 seconds...\nRun Code Online (Sandbox Code Playgroud)\n因此,代理已成功从服务器运行流程enigmatic-axolotl,并且似乎已完成执行。我的理解是,它然后尝试连接到服务器以更新流程运行的状态。但是,它未能这样做,因为它无法连接到host.docker.internal:4200.
我想知道是否host.docker.internal是有效的主机,因此我使用选项重新启动了代理-a http://localhost:4200。代理成功连接到服务器localhost:4200(在日志中报告这样做),但是,当我再次运行流程时,我收到与之前相同的错误;也就是说,它无法连接到host.docker.internal:4200.
最后,我用 重新运行代理-a http://0.0.0.0:4200。再次,它成功连接到服务器。然后我重新运行流程,但它再次失败。但是,这次它尝试连接到0.0.0.0:4200:
raise ConnectionError(e, request=request)\nrequests.exceptions.ConnectionError: HTTPConnectionPool(host='0.0.0.0', port=4200): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f70738948d0>: Failed to establish a new connection: [Errno 111] Connection refused'))\nRun Code Online (Sandbox Code Playgroud)\n我缺少什么?我假设我需要设置一些配置才能使其工作。
\n小智 5
从 Prefect Server 0.15.5 及更高版本开始,您可能需要执行以下操作
prefect server start --expose。这将允许外部连接到服务器。
您可以在此 Github 问题中找到更多信息:https://github.com/PrefectHQ/prefect/issues/4963
| 归档时间: |
|
| 查看次数: |
1007 次 |
| 最近记录: |