Skip to content

Commit 0713488

Browse files
committed
Resolves #497 - add support for dockerfile
Signed-off-by: Daniel Nephin <[email protected]>
1 parent d39da11 commit 0713488

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

docker/client.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ def attach_socket(self, container, params=None, ws=False):
275275
def build(self, path=None, tag=None, quiet=False, fileobj=None,
276276
nocache=False, rm=False, stream=False, timeout=None,
277277
custom_context=False, encoding=None, pull=True,
278-
forcerm=False):
278+
forcerm=False, dockerfile=None):
279279
remote = context = headers = None
280280
if path is None and fileobj is None:
281281
raise TypeError("Either path or fileobj needs to be provided.")
@@ -302,6 +302,11 @@ def build(self, path=None, tag=None, quiet=False, fileobj=None,
302302
if utils.compare_version('1.8', self._version) >= 0:
303303
stream = True
304304

305+
if dockerfile and utils.compare_version('1.17', self._version) < 0:
306+
raise errors.InvalidVersion(
307+
'dockerfile was only introduced in API version 1.17'
308+
)
309+
305310
u = self._url('/build')
306311
params = {
307312
't': tag,
@@ -310,7 +315,8 @@ def build(self, path=None, tag=None, quiet=False, fileobj=None,
310315
'nocache': nocache,
311316
'rm': rm,
312317
'forcerm': forcerm,
313-
'pull': pull
318+
'pull': pull,
319+
'dockerfile': dockerfile
314320
}
315321

316322
if context is not None:

docs/api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ correct value (e.g `gzip`).
6363
* encoding (str): The encoding for a stream. Set to `gzip` for compressing
6464
* pull (bool): Downloads any updates to the FROM image in Dockerfiles
6565
* forcerm (bool): Always remove intermediate containers, even after unsuccessful builds
66+
* dockerfile (str): path within the build context to the Dockerfile
6667

6768
**Returns** (generator): A generator of the build output
6869

tests/test.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2095,6 +2095,12 @@ def test_build_remote_with_registry_auth(self):
20952095
except Exception as e:
20962096
self.fail('Command should not raise exception: {0}'.format(e))
20972097

2098+
def test_build_container_with_named_dockerfile(self):
2099+
try:
2100+
self.client.build('.', dockerfile='nameddockerfile')
2101+
except Exception as e:
2102+
self.fail('Command should not raise exception: {0}'.format(e))
2103+
20982104
#######################
20992105
# PY SPECIFIC TESTS #
21002106
#######################

0 commit comments

Comments
 (0)