-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Since docker 1.4.0, .dockerignore files became .gitignore-like in that there is a difference between foo vs. foo/. The former can match files, symbolic links, etc. while the latter only matches the directory foo. This problem was also reported in: docker/compose#543.
Unfortunately, docker-py cannot handle foo/ syntax, and I suspect it's missing some other major cases. The reason is here:
docker-py/docker/utils/utils.py
Lines 67 to 68 in 0b78d7a
| def fnmatch_any(relpath, patterns): | |
| return any([fnmatch(relpath, pattern) for pattern in patterns]) |
os.walk which output directories without trailing slash and fnmatch can't match:
>>> from fnmatch import fnmatch
>>> fnmatch('src', 'src/')
FalseMy first thought was to suggest that docker-py use pathspec (https://github.com/cpburnz/python-path-specification) which implements .gitignore-style matching. However, I don't think the way that docker implements .dockerignore matching mirrors .gitignore-style matching (see: https://github.com/docker/docker/blob/master/pkg/fileutils/fileutils.go).
Does anyone have good ideas on an elegant fix?
As a temporary fix to anyone who stumbles on this issue, try to keep your .dockerignore file as simple as possible if you find that certain directories are not being ignored.