Skip to content

.dockerignore ignores trailing slash on directories #581

@mikexstudios

Description

@mikexstudios

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions