Unable to prepare context when Dockerfile is in subdirectory and hooks/build exists

I have an app where I am storing my Dockerfile under build/packages/. Because I require hooks, I have build hooks under build/packages/hooks/

Running an automated build with with Dockerfile Location of build/package/Dockerfile and Build Context of /, I get the following error.

unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /src/b4vy4tejxehkb89w3zpukbo/build/package/build: no such file or directory

One interesting piece is that during this build, PWD is /src/${BUILD_CODE}/build/package/. It seems that the build is CHDIRing to the Dockerfile Location directory, which is counter intuitive.

I have tried other combinations that have been unsuccessful:

  • hooks/ under the root of the repository never runs the hooks as the hooks directory needs to be UNDER the Dockerfile directory to run.
  • Hard-coding ../.. to the end of docker build statement does not work
  • Soft-coding /src/${BUILD_CODE}/ to the end of docker build statement does not work
  • Soft-coding /src/${BUILD_CODE}${BUILD_PATH} to the end of docker build statement does not work

Why are you CHDIRing to the Dockerfile directory? That means my hooks either (a) have to know which directory they are in or (b) be custom-coded to DockerHub’s /src/$BUILD_CODE directory.