Skip to content

Commit ce40730

Browse files
committed
Add special cases for .dockerignore
Fixes #498 Allowing `Dockerfile` and `.dockerignore` in the exclusion filter completely breaks the build on docker < 1.5 In Docker 1.5 these entries are treated as special cases when included in the .dockerignore and are still sent as part of the context. The daemon ends up excluding them from any `ADD`, `COPY`, and cache validation. Signed-off-by: Brian Goff <[email protected]>
1 parent 5ce02b9 commit ce40730

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

docker/client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,12 @@ def build(self, path=None, tag=None, quiet=False, fileobj=None,
297297
if os.path.exists(dockerignore):
298298
with open(dockerignore, 'r') as f:
299299
exclude = list(filter(bool, f.read().split('\n')))
300+
# These are handled by the docker daemon and should not be
301+
# excluded on the client
302+
if 'Dockerfile' in exclude:
303+
exclude.remove('Dockerfile')
304+
if '.dockerignore' in exclude:
305+
exclude.remove(".dockerignore")
300306
context = utils.tar(path, exclude=exclude)
301307

302308
if utils.compare_version('1.8', self._version) >= 0:

tests/integration_test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,6 +1311,8 @@ def runTest(self):
13111311
with open(os.path.join(base_dir, '.dockerignore'), 'w') as f:
13121312
f.write("\n".join([
13131313
'node_modules',
1314+
'Dockerfile',
1315+
'.dockerginore',
13141316
'', # empty line
13151317
]))
13161318

@@ -1329,6 +1331,8 @@ def runTest(self):
13291331
chunk = chunk.decode('utf-8')
13301332
logs += chunk
13311333
self.assertFalse('node_modules' in logs)
1334+
self.assertFalse('Dockerfile' in logs)
1335+
self.assertFalse('.dockerginore' in logs)
13321336
self.assertTrue('not-ignored' in logs)
13331337

13341338
#######################

0 commit comments

Comments
 (0)