-
Notifications
You must be signed in to change notification settings - Fork 18.9k
wildcard directories not implemented correctly in dockerignore #41433
Description
Description
wildcard directory matching in dockerignore (the double asterisk **) is not implemented correctly and buggy in some cases
Steps to reproduce the issue:
- Dockerfile:
FROM busybox
WORKDIR /src
ADD . .
RUN find .
- .dockerignore:
**/c
!a/b/c/include.txt
.git
-
Create files "a/b/c/include.txt" and "a/b/c/exclude.txt"
-
Run
docker build --no-cache .
Describe the results you received:
a/b/c/exclude.txt should be ignored
Describe the results you expected:
a/b/c/exclude.txt is included in the docker context
Additional information you deem important (e.g. issue happens only occasionally):
This repo has a more complete explanation of the bug:
https://github.com/tilt-dev/dockerignore-wildcard-bug
The underlying bug is this code:
https://github.com/moby/moby/blob/v19.03.12/pkg/fileutils/fileutils.go#L83
which assumes that the number of directory separators in the pattern can be used to determine the "directory" length, which is not a correct assumption when wildcards are present.
Interestingly, the exclude pattern is necessary to reproduce this problem. That's because this code:
https://github.com/moby/moby/blob/v19.03.12/pkg/archive/archive.go#L843
skips directories purely as an optimization. Adding an exclusion pattern (!a/b/c/include.txt) makes this code go down the "slow" codepath.
Output of docker version:
Client: Docker Engine - Community
Version: 19.03.11
API version: 1.40
Go version: go1.13.10
Git commit: 42e35e61f3
Built: Mon Jun 1 09:12:22 2020
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 19.03.11
API version: 1.40 (minimum version 1.12)
Go version: go1.13.10
Git commit: 42e35e61f3
Built: Mon Jun 1 09:10:54 2020
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.2.13
GitCommit: 7ad184331fa3e55e52b890ea95e65ba581ae3429
runc:
Version: 1.0.0-rc10
GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd
docker-init:
Version: 0.18.0
GitCommit: fec3683