How to set custom context for docker.build in jenkinsfile
It turns out that I was pulling a previous version (1.6) of the docker-pipeline-plugin. The function in question has been since updated (1.7) to allow the second parameter to designate a Dockerfile location outside the context.
The updated statement in my Jenkinsfile is:
return docker.build("db", "-f docker/db/Dockerfile .")
And this allows my container to build without modifying the expected context of the developer's docker-compose or Dockerfiles.
The build() method builds the Dockerfile in the current directory by default. This can be overridden by providing a directory path containing a Dockerfile as the second argument of the build() method, for example:
node {
checkout scm
def testImage = docker.build("test-image", "./dockerfiles/test")
testImage.inside {
sh 'make test'
}
}