Repository: docker/docker-py

Issue:
WorkingDir not yet implemented
Not entirely sure - but it seems to me that the WorkingDir flag is not yet implemented? Did I miss something? Let me know if this is the case - I can write a fix and submit it.



Discussion:
That's correct. Feel free to take a crack at it, I'll happily review it!


Resolving patch:
diff --git a/docker/client.py b/docker/client.py
--- a/docker/client.py
+++ b/docker/client.py
@@ -122,7 +122,8 @@ def _container_config(self, image, command, hostname=None, user=None,
                           detach=False, stdin_open=False, tty=False,
                           mem_limit=0, ports=None, environment=None, dns=None,
                           volumes=None, volumes_from=None,
-                          network_disabled=False):
+                          network_disabled=False, entrypoint=None,
+                          cpu_shares=None, working_dir=None):
         if isinstance(command, six.string_types):
             command = shlex.split(str(command))
         if isinstance(environment, dict):
@@ -175,7 +176,10 @@ def _container_config(self, image, command, hostname=None, user=None,
             'Image':        image,
             'Volumes':      volumes,
             'VolumesFrom':  volumes_from,
-            'NetworkDisabled': network_disabled
+            'NetworkDisabled': network_disabled,
+            'Entrypoint':   entrypoint,
+            'CpuShares':    cpu_shares,
+            'WorkingDir':    working_dir
         }
 
     def _post_json(self, url, data, **kwargs):
@@ -406,11 +410,13 @@ def create_container(self, image, command=None, hostname=None, user=None,
                          detach=False, stdin_open=False, tty=False,
                          mem_limit=0, ports=None, environment=None, dns=None,
                          volumes=None, volumes_from=None,
-                         network_disabled=False, name=None):
+                         network_disabled=False, name=None, entrypoint=None,
+                         cpu_shares=None, working_dir=None):
 
         config = self._container_config(
             image, command, hostname, user, detach, stdin_open, tty, mem_limit,
-            ports, environment, dns, volumes, volumes_from, network_disabled
+            ports, environment, dns, volumes, volumes_from, network_disabled,
+            entrypoint, cpu_shares, working_dir
         )
         return self.create_container_from_config(config, name)
 


Test patch:
diff --git a/tests/test.py b/tests/test.py
--- a/tests/test.py
+++ b/tests/test.py
@@ -229,6 +229,72 @@ def test_create_container_with_ports(self):
         self.assertEqual(args[1]['headers'],
                          {'Content-Type': 'application/json'})
 
+    def test_create_container_with_entrypoint(self):
+        try:
+            self.client.create_container('busybox', 'hello',
+                                         entrypoint='cowsay')
+        except Exception as e:
+            self.fail('Command should not raise exception: {0}'.format(e))
+
+        args = fake_request.call_args
+        self.assertEqual(args[0][0],
+                         'unix://var/run/docker.sock/v1.6/containers/create')
+        self.assertEqual(json.loads(args[1]['data']),
+                         json.loads('''
+                            {"Tty": false, "Image": "busybox",
+                             "Cmd": ["hello"], "AttachStdin": false,
+                             "Memory": 0,
+                             "AttachStderr": true,
+                             "AttachStdout": true, "OpenStdin": false,
+                             "NetworkDisabled": false,
+                             "Entrypoint": "cowsay"}'''))
+        self.assertEqual(args[1]['headers'],
+                         {'Content-Type': 'application/json'})
+
+    def test_create_container_with_cpu_shares(self):
+        try:
+            self.client.create_container('busybox', 'ls',
+                                         cpu_shares=5)
+        except Exception as e:
+            self.fail('Command should not raise exception: {0}'.format(e))
+
+        args = fake_request.call_args
+        self.assertEqual(args[0][0],
+                         'unix://var/run/docker.sock/v1.6/containers/create')
+        self.assertEqual(json.loads(args[1]['data']),
+                         json.loads('''
+                            {"Tty": false, "Image": "busybox",
+                             "Cmd": ["ls"], "AttachStdin": false,
+                             "Memory": 0,
+                             "AttachStderr": true,
+                             "AttachStdout": true, "OpenStdin": false,
+                             "NetworkDisabled": false,
+                             "CpuShares": 5}'''))
+        self.assertEqual(args[1]['headers'],
+                         {'Content-Type': 'application/json'})
+
+    def test_create_container_with_working_dir(self):
+        try:
+            self.client.create_container('busybox', 'ls',
+                                         working_dir='/root')
+        except Exception as e:
+            self.fail('Command should not raise exception: {0}'.format(e))
+
+        args = fake_request.call_args
+        self.assertEqual(args[0][0],
+                         'unix://var/run/docker.sock/v1.6/containers/create')
+        self.assertEqual(json.loads(args[1]['data']),
+                         json.loads('''
+                            {"Tty": false, "Image": "busybox",
+                             "Cmd": ["ls"], "AttachStdin": false,
+                             "Memory": 0,
+                             "AttachStderr": true,
+                             "AttachStdout": true, "OpenStdin": false,
+                             "NetworkDisabled": false,
+                             "WorkingDir": "/root"}'''))
+        self.assertEqual(args[1]['headers'],
+                         {'Content-Type': 'application/json'})
+
     def test_create_named_container(self):
         try:
             self.client.create_container('busybox', 'true',