summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Nephin <dnephin@gmail.com>2015-02-20 21:19:34 -0500
committerDaniel Nephin <dnephin@gmail.com>2015-02-20 21:20:21 -0500
commit0713488faca9a473135021ad5425bf216ab54ba4 (patch)
tree4301b8d943e6470c6c53d5c4e3cb5e7577b275a7
parentd39da1167975aaeb6c423b99621ecda1223477b8 (diff)
downloaddocker-py-0713488faca9a473135021ad5425bf216ab54ba4.tar.gz
Resolves #497 - add support for dockerfile
Signed-off-by: Daniel Nephin <dnephin@gmail.com>
-rw-r--r--docker/client.py10
-rw-r--r--docs/api.md1
-rw-r--r--tests/test.py6
3 files changed, 15 insertions, 2 deletions
diff --git a/docker/client.py b/docker/client.py
index f920229..26adf28 100644
--- a/docker/client.py
+++ b/docker/client.py
@@ -275,7 +275,7 @@ class Client(requests.Session):
def build(self, path=None, tag=None, quiet=False, fileobj=None,
nocache=False, rm=False, stream=False, timeout=None,
custom_context=False, encoding=None, pull=True,
- forcerm=False):
+ forcerm=False, dockerfile=None):
remote = context = headers = None
if path is None and fileobj is None:
raise TypeError("Either path or fileobj needs to be provided.")
@@ -302,6 +302,11 @@ class Client(requests.Session):
if utils.compare_version('1.8', self._version) >= 0:
stream = True
+ if dockerfile and utils.compare_version('1.17', self._version) < 0:
+ raise errors.InvalidVersion(
+ 'dockerfile was only introduced in API version 1.17'
+ )
+
u = self._url('/build')
params = {
't': tag,
@@ -310,7 +315,8 @@ class Client(requests.Session):
'nocache': nocache,
'rm': rm,
'forcerm': forcerm,
- 'pull': pull
+ 'pull': pull,
+ 'dockerfile': dockerfile
}
if context is not None:
diff --git a/docs/api.md b/docs/api.md
index a523878..9e550a9 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -63,6 +63,7 @@ correct value (e.g `gzip`).
* encoding (str): The encoding for a stream. Set to `gzip` for compressing
* pull (bool): Downloads any updates to the FROM image in Dockerfiles
* forcerm (bool): Always remove intermediate containers, even after unsuccessful builds
+* dockerfile (str): path within the build context to the Dockerfile
**Returns** (generator): A generator of the build output
diff --git a/tests/test.py b/tests/test.py
index f55027a..b39410c 100644
--- a/tests/test.py
+++ b/tests/test.py
@@ -2095,6 +2095,12 @@ class DockerClientTest(Cleanup, unittest.TestCase):
except Exception as e:
self.fail('Command should not raise exception: {0}'.format(e))
+ def test_build_container_with_named_dockerfile(self):
+ try:
+ self.client.build('.', dockerfile='nameddockerfile')
+ except Exception as e:
+ self.fail('Command should not raise exception: {0}'.format(e))
+
#######################
# PY SPECIFIC TESTS #
#######################