Skip to content
This repository was archived by the owner on Mar 23, 2023. It is now read-only.
This repository was archived by the owner on Mar 23, 2023. It is now read-only.

dockerignore include / exclude computation doesn't match Docker's #159

@cjerdonek

Description

@cjerdonek

I encountered a situation where docker-osx-dev wasn't syncing / noticing changes to certain files that it should have. Here is a reduced test case.

.dockerignore contents:

*
!foo/

Directory contents:

.dockerignore
bar/
  buzz.txt
foo/
  bar/
    buzz.txt
  buzz.txt

However, files in foo/bar aren't synced / watched:

$ docker-osx-dev sync -s .
[INFO] Using sync paths from command line args: .
[INFO] Complete list of paths to sync: /Users/chris/temp-sync
[INFO] Using excludes from ignore file .dockerignore: bar foo
[INFO] Complete list of paths to exclude: bar foo
[INFO] Using includes from ignore file .dockerignore: foo/
[INFO] Complete list of paths to include: foo/
[INFO] Starting docker-osx-dev file syncing
[INFO] Testing if docker machine is running
[INFO] Installing rsync in the Docker Host image
[INFO] Performing initial sync of paths: /Users/chris/temp-sync
[INFO] Syncing temp-sync/: cd+++++++
[INFO] Syncing temp-sync/.dockerignore: <f+++++++
[INFO] Syncing temp-sync/foo/: cd+++++++
[INFO] Syncing temp-sync/foo/buzz.txt: <f+++++++
[INFO] Initial sync done
[INFO] Watching: /Users/chris/temp-sync

I did confirm using a Dockerfile with a line like "COPY . test/" that Docker's behavior is not to ignore foo/bar. The issue above is that docker-osx-dev is adding "bar" as an unrooted exclude pattern rather than a rooted one, and so excluding "bar" when it appears as a subdirectory.

This is from the Dockerfile docs here:

For the purposes of matching, the root of the context is considered to be both the working and the root directory. For example, the patterns /foo/bar and foo/bar both exclude a file or directory named bar in the foo subdirectory of PATH or in the root of the git repository located at URL. Neither excludes anything else.

The idea to use "*" at the beginning to specify a whitelist is something that the same docs above suggest:

Finally, you may want to specify which files to include in the context, rather than which to exclude. To achieve this, specify * as the first pattern, followed by one or more ! exception patterns.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions