oboki commented on code in PR #38466:
URL: https://github.com/apache/airflow/pull/38466#discussion_r1538292974


##########
airflow/providers/docker/operators/docker.py:
##########
@@ -343,13 +345,21 @@ def hook(self) -> DockerHook:
             assert_hostname=self.tls_hostname,
             ssl_version=self.tls_ssl_version,
         )
-        return DockerHook(
-            docker_conn_id=self.docker_conn_id,
-            base_url=self.docker_url,
-            version=self.api_version,
-            tls=tls_config,
-            timeout=self.timeout,
-        )
+        hook = None
+        for url in self.docker_url:
+            hook = DockerHook(
+                docker_conn_id=self.docker_conn_id,
+                base_url=url,
+                version=self.api_version,
+                tls=tls_config,
+                timeout=self.timeout
+            )
+            try:
+                hook.get_conn()

Review Comment:
   I tested it with the following code:
   
   ```python
   from airflow.providers.docker.operators.docker import DockerOperator
   op = DockerOperator(
       image="ubuntu:latest",
       task_id='test',
       docker_url=[
           "tcp://localhost:2375",
           "unix://foo/bar/spam.egg",
           "unix:///var/run/docker.sock"
       ]
   )
   print(op.hook is None)
   print(op.hook.get_conn().ping())
   ```
   
   It seems to create a proper connection after encountering 
`NewConnectionError`, `FileNotFoundError` errors.
   
   ```log
   [2024-03-26T06:57:12.286+0900] {docker.py:360} ERROR - Failed to establish 
connection to Docker host tcp://localhost:2375: Error while fetching server API 
version: HTTPConnectionPool(host='localhost', port=2375): Max retries exceeded 
with url: /version (Caused by 
NewConnectionError('<urllib3.connection.HTTPConnection object at 
0x7f8126b46320>: Failed to establish a new connection: [Errno 111] Connection 
refused'))
   [2024-03-26T06:57:12.288+0900] {docker.py:360} ERROR - Failed to establish 
connection to Docker host unix://foo/bar/spam.egg: Error while fetching server 
API version: ('Connection aborted.', FileNotFoundError(2, 'No such file or 
directory'))
   False
   True
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to