prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  build local docker image using docker python api
  for the edl client to build docker image locally, we need a wrapper for docker python sdk:  https://pypi.org/project/docker firstly.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `elasticdl/client/client.py`
  Content:
  ```
  1 import os
  2 import inspect
  3 import shutil
  4 import time
  5 import getpass
  6 from string import Template
  7 
  8 def run(model_class, train_data_dir=None, 
  9         num_epoch=1, minibatch_size=10, 
  10         record_per_task=100, num_worker=1, grads_to_wait=2):
  11     m_path, m_file = _getModelFile()
  12     m_file_in_docker = "/model/" + m_file 
  13     timestamp = int(round(time.time() * 1000))
  14     _build_docker_image(m_path, m_file, m_file_in_docker, timestamp)
  15     yaml_file = _generate_yaml(m_file_in_docker, model_class.__name__, train_data_dir=train_data_dir, 
  16             num_epoch=num_epoch, minibatch_size=minibatch_size, 
  17             record_per_task=record_per_task, num_worker=num_worker, 
  18             grads_to_wait=grads_to_wait, timestamp=timestamp)
  19     _submit(yaml_file)
  20 
  21 def _getModelFile():
  22     m_file = inspect.currentframe().f_back.f_back.f_code.co_filename
  23     m_path = os.path.abspath(os.path.dirname(m_file))
  24     return m_path, m_file
  25 
  26 def _build_docker_image(m_path, m_file, m_file_in_docker, timestamp):
  27     d_path = os.path.abspath(os.path.dirname(
  28         inspect.currentframe().f_back.f_code.co_filename))
  29     new_dfile = m_path + "/Dockerfile"
  30     shutil.copyfile(d_path + "/../Dockerfile.dev", new_dfile)
  31 
  32     with open(new_dfile, 'a') as df:
  33         df.write("COPY " + m_file + " " + m_file_in_docker)
  34     val = os.system('docker build -t elasticdl:dev_' + str(timestamp) + ' -f Dockerfile .')
  35 
  36     # TODO: upload docker image to docker hub.
  37 
  38 def _generate_yaml(m_file, m_class,
  39                    train_data_dir=None, num_epoch=1,
  40                    minibatch_size=10, record_per_task=100, 
  41                    num_worker=1, grads_to_wait=2, timestamp=1):
  42   YAML_TEMPLATE = """
  43   apiVersion: v1
  44   kind: Pod
  45   metadata:
  46     name: elasticdl-master-$timestamp
  47     labels:
  48       purpose: test-command
  49   spec:
  50     containers:
  51     - name: elasticdl-master-$timestamp
  52       image: elasticdl:dev_$timestamp
  53       command: ["python"]
  54       args: ["-m", "elasticdl.master.main",
  55            "--model-file", "$m_file",
  56            "--num_worker", "$num_worker",
  57            "--worker_image", "elasticdl:dev_$timestamp",
  58            "--job_name", "elasticdl-$timestamp",
  59            "--model-class", "$m_class",
  60            "--train_data_dir", "$train_data_dir",
  61            "--num_epoch", "$num_epoch",
  62            "--grads_to_wait", "$grads_to_wait",
  63            "--minibatch_size", "$minibatch_size",
  64            "--record_per_task", "$record_per_task"]
  65       imagePullPolicy: Never
  66       env:
  67       - name: MY_POD_IP
  68         valueFrom:
  69           fieldRef:
  70             fieldPath: status.podIP
  71     restartPolicy: Never
  72   """
  73   t = Template(YAML_TEMPLATE)
  74   yaml_file = 'job_desc.yaml'
  75   with open(yaml_file, "w") as yaml:
  76       yaml.write(t.substitute(m_file=m_file, m_class=m_class, 
  77           train_data_dir=train_data_dir, 
  78           timestamp=timestamp, num_worker=num_worker, num_epoch=num_epoch,
  79           minibatch_size=minibatch_size, record_per_task=record_per_task,
  80           user=getpass.getuser(), grads_to_wait=grads_to_wait))
  81   return yaml_file
  82 
  83 def _submit(yaml_file):
  84     os.system('kubectl create -f ' + yaml_file)
  85
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/elasticdl/client/client.py b/elasticdl/client/client.py
  --- a/elasticdl/client/client.py
  +++ b/elasticdl/client/client.py
  @@ -4,6 +4,8 @@
   import time
   import getpass
   from string import Template
  +import docker
  +
   
   def run(model_class, train_data_dir=None, 
           num_epoch=1, minibatch_size=10, 
  @@ -31,7 +33,9 @@
   
       with open(new_dfile, 'a') as df:
           df.write("COPY " + m_file + " " + m_file_in_docker)
  -    val = os.system('docker build -t elasticdl:dev_' + str(timestamp) + ' -f Dockerfile .')
  +    client = docker.APIClient(base_url='unix://var/run/docker.sock') 
  +    for line in client.build(dockerfile='Dockerfile', path='.', tag='elasticdl:dev_' + str(timestamp)):
  +        print(str(line, encoding = "utf-8"))
   
       # TODO: upload docker image to docker hub.
  
verification_info: {"golden_diff": "diff --git a/elasticdl/client/client.py b/elasticdl/client/client.py\n--- a/elasticdl/client/client.py\n+++ b/elasticdl/client/client.py\n@@ -4,6 +4,8 @@\n import time\n import getpass\n from string import Template\n+import docker\n+\n \n def run(model_class, train_data_dir=None, \n         num_epoch=1, minibatch_size=10, \n@@ -31,7 +33,9 @@\n \n     with open(new_dfile, 'a') as df:\n         df.write(\"COPY \" + m_file + \" \" + m_file_in_docker)\n-    val = os.system('docker build -t elasticdl:dev_' + str(timestamp) + ' -f Dockerfile .')\n+    client = docker.APIClient(base_url='unix://var/run/docker.sock') \n+    for line in client.build(dockerfile='Dockerfile', path='.', tag='elasticdl:dev_' + str(timestamp)):\n+        print(str(line, encoding = \"utf-8\"))\n \n     # TODO: upload docker image to docker hub.\n", "issue": "build local docker image using docker python api\nfor the edl client to build docker image locally, we need a wrapper for docker python sdk:  https://pypi.org/project/docker firstly.\n", "before_files": [{"content": "import os\nimport inspect\nimport shutil\nimport time\nimport getpass\nfrom string import Template\n\ndef run(model_class, train_data_dir=None, \n        num_epoch=1, minibatch_size=10, \n        record_per_task=100, num_worker=1, grads_to_wait=2):\n    m_path, m_file = _getModelFile()\n    m_file_in_docker = \"/model/\" + m_file \n    timestamp = int(round(time.time() * 1000))\n    _build_docker_image(m_path, m_file, m_file_in_docker, timestamp)\n    yaml_file = _generate_yaml(m_file_in_docker, model_class.__name__, train_data_dir=train_data_dir, \n            num_epoch=num_epoch, minibatch_size=minibatch_size, \n            record_per_task=record_per_task, num_worker=num_worker, \n            grads_to_wait=grads_to_wait, timestamp=timestamp)\n    _submit(yaml_file)\n\ndef _getModelFile():\n    m_file = inspect.currentframe().f_back.f_back.f_code.co_filename\n    m_path = os.path.abspath(os.path.dirname(m_file))\n    return m_path, m_file\n\ndef _build_docker_image(m_path, m_file, m_file_in_docker, timestamp):\n    d_path = os.path.abspath(os.path.dirname(\n        inspect.currentframe().f_back.f_code.co_filename))\n    new_dfile = m_path + \"/Dockerfile\"\n    shutil.copyfile(d_path + \"/../Dockerfile.dev\", new_dfile)\n\n    with open(new_dfile, 'a') as df:\n        df.write(\"COPY \" + m_file + \" \" + m_file_in_docker)\n    val = os.system('docker build -t elasticdl:dev_' + str(timestamp) + ' -f Dockerfile .')\n\n    # TODO: upload docker image to docker hub.\n\ndef _generate_yaml(m_file, m_class,\n                   train_data_dir=None, num_epoch=1,\n                   minibatch_size=10, record_per_task=100, \n                   num_worker=1, grads_to_wait=2, timestamp=1):\n  YAML_TEMPLATE = \"\"\"\n  apiVersion: v1\n  kind: Pod\n  metadata:\n    name: elasticdl-master-$timestamp\n    labels:\n      purpose: test-command\n  spec:\n    containers:\n    - name: elasticdl-master-$timestamp\n      image: elasticdl:dev_$timestamp\n      command: [\"python\"]\n      args: [\"-m\", \"elasticdl.master.main\",\n           \"--model-file\", \"$m_file\",\n           \"--num_worker\", \"$num_worker\",\n           \"--worker_image\", \"elasticdl:dev_$timestamp\",\n           \"--job_name\", \"elasticdl-$timestamp\",\n           \"--model-class\", \"$m_class\",\n           \"--train_data_dir\", \"$train_data_dir\",\n           \"--num_epoch\", \"$num_epoch\",\n           \"--grads_to_wait\", \"$grads_to_wait\",\n           \"--minibatch_size\", \"$minibatch_size\",\n           \"--record_per_task\", \"$record_per_task\"]\n      imagePullPolicy: Never\n      env:\n      - name: MY_POD_IP\n        valueFrom:\n          fieldRef:\n            fieldPath: status.podIP\n    restartPolicy: Never\n  \"\"\"\n  t = Template(YAML_TEMPLATE)\n  yaml_file = 'job_desc.yaml'\n  with open(yaml_file, \"w\") as yaml:\n      yaml.write(t.substitute(m_file=m_file, m_class=m_class, \n          train_data_dir=train_data_dir, \n          timestamp=timestamp, num_worker=num_worker, num_epoch=num_epoch,\n          minibatch_size=minibatch_size, record_per_task=record_per_task,\n          user=getpass.getuser(), grads_to_wait=grads_to_wait))\n  return yaml_file\n\ndef _submit(yaml_file):\n    os.system('kubectl create -f ' + yaml_file)\n", "path": "elasticdl/client/client.py"}], "after_files": [{"content": "import os\nimport inspect\nimport shutil\nimport time\nimport getpass\nfrom string import Template\nimport docker\n\n\ndef run(model_class, train_data_dir=None, \n        num_epoch=1, minibatch_size=10, \n        record_per_task=100, num_worker=1, grads_to_wait=2):\n    m_path, m_file = _getModelFile()\n    m_file_in_docker = \"/model/\" + m_file \n    timestamp = int(round(time.time() * 1000))\n    _build_docker_image(m_path, m_file, m_file_in_docker, timestamp)\n    yaml_file = _generate_yaml(m_file_in_docker, model_class.__name__, train_data_dir=train_data_dir, \n            num_epoch=num_epoch, minibatch_size=minibatch_size, \n            record_per_task=record_per_task, num_worker=num_worker, \n            grads_to_wait=grads_to_wait, timestamp=timestamp)\n    _submit(yaml_file)\n\ndef _getModelFile():\n    m_file = inspect.currentframe().f_back.f_back.f_code.co_filename\n    m_path = os.path.abspath(os.path.dirname(m_file))\n    return m_path, m_file\n\ndef _build_docker_image(m_path, m_file, m_file_in_docker, timestamp):\n    d_path = os.path.abspath(os.path.dirname(\n        inspect.currentframe().f_back.f_code.co_filename))\n    new_dfile = m_path + \"/Dockerfile\"\n    shutil.copyfile(d_path + \"/../Dockerfile.dev\", new_dfile)\n\n    with open(new_dfile, 'a') as df:\n        df.write(\"COPY \" + m_file + \" \" + m_file_in_docker)\n    client = docker.APIClient(base_url='unix://var/run/docker.sock') \n    for line in client.build(dockerfile='Dockerfile', path='.', tag='elasticdl:dev_' + str(timestamp)):\n        print(str(line, encoding = \"utf-8\"))\n\n    # TODO: upload docker image to docker hub.\n\ndef _generate_yaml(m_file, m_class,\n                   train_data_dir=None, num_epoch=1,\n                   minibatch_size=10, record_per_task=100, \n                   num_worker=1, grads_to_wait=2, timestamp=1):\n  YAML_TEMPLATE = \"\"\"\n  apiVersion: v1\n  kind: Pod\n  metadata:\n    name: elasticdl-master-$timestamp\n    labels:\n      purpose: test-command\n  spec:\n    containers:\n    - name: elasticdl-master-$timestamp\n      image: elasticdl:dev_$timestamp\n      command: [\"python\"]\n      args: [\"-m\", \"elasticdl.master.main\",\n           \"--model-file\", \"$m_file\",\n           \"--num_worker\", \"$num_worker\",\n           \"--worker_image\", \"elasticdl:dev_$timestamp\",\n           \"--job_name\", \"elasticdl-$timestamp\",\n           \"--model-class\", \"$m_class\",\n           \"--train_data_dir\", \"$train_data_dir\",\n           \"--num_epoch\", \"$num_epoch\",\n           \"--grads_to_wait\", \"$grads_to_wait\",\n           \"--minibatch_size\", \"$minibatch_size\",\n           \"--record_per_task\", \"$record_per_task\"]\n      imagePullPolicy: Never\n      env:\n      - name: MY_POD_IP\n        valueFrom:\n          fieldRef:\n            fieldPath: status.podIP\n    restartPolicy: Never\n  \"\"\"\n  t = Template(YAML_TEMPLATE)\n  yaml_file = 'job_desc.yaml'\n  with open(yaml_file, \"w\") as yaml:\n      yaml.write(t.substitute(m_file=m_file, m_class=m_class, \n          train_data_dir=train_data_dir, \n          timestamp=timestamp, num_worker=num_worker, num_epoch=num_epoch,\n          minibatch_size=minibatch_size, record_per_task=record_per_task,\n          user=getpass.getuser(), grads_to_wait=grads_to_wait))\n  return yaml_file\n\ndef _submit(yaml_file):\n    os.system('kubectl create -f ' + yaml_file)\n", "path": "elasticdl/client/client.py"}]}