Repository: sql-machine-learning/elasticdl

Issue:
Expose local docker host args
Currently, we use docker python api to build docker images locally. The docker host is be set to "unix://var/run/docker.sock" by default. Please refer to 

https://github.com/sql-machine-learning/elasticdl/blob/1727e2368abffe5b8179c26c9aefa420e4bbc8cd/elasticdl/python/elasticdl/image_builder.py#L67-L69

However, sometimes, we may use another docker host. For example, we may use docker host of minikube. The docker host will be an another one. Or even we have to connect a docker host in remote.

So, the local docker host related args have to be exposed.


Discussion:

Resolving patch:
diff --git a/elasticdl/python/common/args.py b/elasticdl/python/common/args.py
--- a/elasticdl/python/common/args.py
+++ b/elasticdl/python/common/args.py
@@ -161,6 +161,17 @@ def add_common_params(parser):
         help="The file that contains user-defined cluster specification",
         default="",
     )
+    parser.add_argument(
+        "--docker_base_url",
+        help="URL to the Docker server",
+        default="unix://var/run/docker.sock",
+    )
+    parser.add_argument(
+        "--docker_tlscert", help="Path to Docker client cert", default=""
+    )
+    parser.add_argument(
+        "--docker_tlskey", help="Path to Docker client key", default=""
+    )
 
 
 def add_train_params(parser):
diff --git a/elasticdl/python/elasticdl/api.py b/elasticdl/python/elasticdl/api.py
--- a/elasticdl/python/elasticdl/api.py
+++ b/elasticdl/python/elasticdl/api.py
@@ -15,6 +15,9 @@ def train(args):
         docker_image_prefix=args.docker_image_prefix,
         extra_pypi=args.extra_pypi_index,
         cluster_spec=args.cluster_spec,
+        docker_base_url=args.docker_base_url,
+        docker_tlscert=args.docker_tlscert,
+        docker_tlskey=args.docker_tlskey,
     )
 
     container_args = [
@@ -96,6 +99,9 @@ def evaluate(args):
         docker_image_prefix=args.docker_image_prefix,
         extra_pypi=args.extra_pypi_index,
         cluster_spec=args.cluster_spec,
+        docker_base_url=args.docker_base_url,
+        docker_tlscert=args.docker_tlscert,
+        docker_tlskey=args.docker_tlskey,
     )
     container_args = [
         "-m",
@@ -149,6 +155,9 @@ def predict(args):
         docker_image_prefix=args.docker_image_prefix,
         extra_pypi=args.extra_pypi_index,
         cluster_spec=args.cluster_spec,
+        docker_base_url=args.docker_base_url,
+        docker_tlscert=args.docker_tlscert,
+        docker_tlskey=args.docker_tlskey,
     )
     container_args = [
         "-m",
diff --git a/elasticdl/python/elasticdl/image_builder.py b/elasticdl/python/elasticdl/image_builder.py
--- a/elasticdl/python/elasticdl/image_builder.py
+++ b/elasticdl/python/elasticdl/image_builder.py
@@ -15,6 +15,9 @@ def build_and_push_docker_image(
     base_image="",
     extra_pypi="",
     cluster_spec="",
+    docker_base_url="unix://var/run/docker.sock",
+    docker_tlscert="",
+    docker_tlskey="",
 ):
     """Build and push a Docker image containing ElasticDL and the model
 zoo.  The parameter model_zoo could be a local directory or an URL.
@@ -65,7 +68,13 @@ def build_and_push_docker_image(
             )
 
         image_name = _generate_unique_image_name(docker_image_prefix)
-        client = docker.APIClient(base_url="unix://var/run/docker.sock")
+        if docker_tlscert and docker_tlskey:
+            tls_config = docker.tls.TLSConfig(
+                client_cert=(docker_tlscert, docker_tlskey)
+            )
+            client = docker.APIClient(base_url=docker_base_url, tls=tls_config)
+        else:
+            client = docker.APIClient(base_url=docker_base_url)
         _build_docker_image(client, ctx_dir, df.name, image_name)
 
         if docker_image_prefix:


Test patch: