Docker context in Container Builder. The Dockerfile must be within the build context

3/16/2017

I'm not understanding the Docker context in Container Builder. I have a Dockerfile under services/device-registry/base/build/docker/php/Dockerfile but I want my build context to be services/device-registry My Container Builder step looks like this:

- name: 'gcr.io/cloud-builders/docker'
  args: [ 'build', '-f', './base/build/docker/php/Dockerfile', '-t', 'gcr.io/$PROJECT_ID/device-registry-php', '.' ]
  dir: 'services/device-registry'
  id: 'device-registry-php'

And I get the error unable to prepare context: The Dockerfile (/workspace/services/device-registry/base/build/docker/php/D‌​ockerfile) must be within the build context (.)

-- Simon I
gcp
google-container-registry
google-kubernetes-engine

1 Answer

11/17/2017

You this is a docker build limitation/by-design. This is not related to Google Container Builder.

Files you're sending into to a docker build command has to be at the SAME or NESTED folders as the Dockerfile. In your command above, it violates this.

-- AhmetB - Google
Source: StackOverflow