Docker Community Forums

Share and learn in the Docker community.

SOLVED: Build Hooks Break Caching


(Mkubilus) #1

I have a repository that uses Docker Cloud infrastructure with cache enabled. If I add a build hook to a project, even a simple one:

docker build -f $DOCKERFILE_PATH -t $IMAGE_NAME .

Caching will no longer work on this project. Remove the hook, cache works, add the hook, cache breaks.

This is a simplified example, but certain project require secrets stored and passed as build-args. Caching should be supported for these projects.

(Mkubilus) #2

When starting the builds we can see that the initial phase has somewhat different output.

No build hook:

Pulling cache layers for ...
KernelVersion: 4.4.0-1060-aws
Components: [{u'Version': u'18.03.1-ee-1-tp5', u'Name': u'Engine', u'Details': {u'KernelVersion': u'4.4.0-1060-aws', u'Os': u'linux', u'BuildTime': u'2018-06-23T07:58:56.000000000+00:00', u'ApiVersion': u'1.37', u'MinAPIVersion': u'1.12', u'GitCommit': u'1b30665', u'Arch': u'amd64', u'Experimental': u'false', u'GoVersion': u'go1.10.2'}}]
Arch: amd64
BuildTime: 2018-06-23T07:58:56.000000000+00:00
ApiVersion: 1.37
Platform: {u'Name': u''}
Version: 18.03.1-ee-1-tp5
MinAPIVersion: 1.12
GitCommit: 1b30665
Os: linux
GoVersion: go1.10.2
Starting build of ....

With build hook:

Pulling cache layers for ...
Executing build hook...
Sending build context to Docker daemon 71.68kB

(Mkubilus) #3

Solved by adding ‘–cache-from’ to the build hook like so:

docker build --cache-from $IMAGE_NAME -f $DOCKERFILE_PATH -t $IMAGE_NAME .