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:
|
def fnmatch_any(relpath, patterns): |
|
return any([fnmatch(relpath, pattern) for pattern in patterns]) |
. docker-py uses directories from
os.walk which output directories without trailing slash and
fnmatch can't match:
>>> from fnmatch import fnmatch
>>> fnmatch('src', 'src/')
False
My 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.
Since docker 1.4.0,
.dockerignorefiles became.gitignore-like in that there is a difference betweenfoovs.foo/. The former can match files, symbolic links, etc. while the latter only matches the directoryfoo. 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
os.walkwhich output directories without trailing slash andfnmatchcan't match:My 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
.dockerignorefile as simple as possible if you find that certain directories are not being ignored.