akki commented on a change in pull request #16932:
URL: https://github.com/apache/airflow/pull/16932#discussion_r669802196



##########
File path: airflow/providers/docker/operators/docker.py
##########
@@ -227,66 +244,82 @@ def get_hook(self) -> DockerHook:
     def _run_image(self) -> Optional[str]:
         """Run a Docker container with the provided image"""
         self.log.info('Starting docker container from image %s', self.image)
+        if not self.cli:
+            raise Exception("The 'cli' should be initialized before!")
+        if self.mount_tmp_dir:
+            with TemporaryDirectory(prefix='airflowtmp', 
dir=self.host_tmp_dir) as host_tmp_dir:
+                tmp_mount = Mount(self.tmp_dir, host_tmp_dir, "bind")
+                try:
+                    return self._run_image_with_mounts(self.mounts + 
[tmp_mount], add_tmp_variable=True)
+                except APIError as e:
+                    if self.host_tmp_dir in str(e):
+                        self.log.warning(
+                            "Using remote engine or docker-in-docker and 
mounting temporary "
+                            "volume from host is not supported. Falling back 
to "
+                            "`mount_tmp_dir=False` mode. You can set 
`mount_tmp_dir` parameter"
+                            " to False to disable mounting and remove the 
warning"
+                        )
+                        return self._run_image_with_mounts(self.mounts, 
add_tmp_variable=False)
+                    else:
+                        raise Exception(str(e))
+                    raise

Review comment:
       Should we just change this to:
   ```suggestion
                       raise
   ```
   
   Because this would catch the `APIError` & raise an `Exception` with the same 
message.
   Also, with this if/else block, I am not sure if the last line `raise` will 
ever get executed.

##########
File path: airflow/providers/docker/operators/docker.py
##########
@@ -88,6 +100,9 @@ class DockerOperator(BaseOperator):
     :type tls_hostname: str or bool
     :param tls_ssl_version: Version of SSL to use when communicating with 
docker daemon.
     :type tls_ssl_version: str
+    :param mount_tmp_dir: Specify whether the temporary directory should be 
bind-mounted
+        from the host to the container

Review comment:
       Might be worth adding something like `Default is True` over here.




-- 
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