Skip to content

Creating build context may take a long time when dockerignore contains an exception to a rule #1276

@bodnarbm

Description

@bodnarbm

Ran into an issue at work where our local builds using docker-compose where taking a significant amount of time more than our builds using the docker cli tool. This only occurred where we had some exception line in the dockerignore file and some other excluded folder that contained a significant amount of files. The below would be an example of the problematic dockerignore file

# Folder containing lots and lots of small files that should be excluded from a build
node_modules

#Other folder that should be excluded
config/env

#Exception to the above rule
!config/env/docker.js

Something like the above resulted in docker-compose taking nearly a minute or more longer to complete the create build context step for one of our images when compared to doing the same using docker cli. This created a lot of frustration in team members trying to do simple 'Change Code -> Rebuild -> Test' development.

I was able to isolate it down to a difference between how docker-py handles exceptions in dockerignore versus how docker handles the exceptions. While docker-py currently conforms to the older algorithm for docker that checked every file for a potential match to the exception, the newer docker versions skip excluded directories completely if their path is not a prefix to some exception rule.

I created a patch that has the algorithm conform to the newer docker algorithm. I'll submit a PR for your review, as I think using the newer algorithm will significantly speed up our build times.

docker-compose version 1.8.0, build f3628c7
docker-py version: 1.9.0
CPython version: 2.7.9
OpenSSL version: OpenSSL 1.0.2h  3 May 2016

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions