Search code examples
openshift

How to use Dockerfile with different name in OCP Git source build


I am trying to create a Git source build of this Dockerfile: https://github.com/WASdev/ci.docker/blob/master/ga/latest/full/Dockerfile.ubi.ibmjava8

I have the following configuration in my BuildConfig:

source:
  git: 
    uri: "https://github.com/WASdev/ci.docker"
    ref: "master"
  contextDir: "ga/latest/full" 

However, the above assumes the use of the Dockerfile filename while I want to use Dockerfile.ubi.ibmjava8 as in docker build -f Dockerfile.ubi.ibmjava8 ..

How can I use Dockerfile.ubi.ibmjava8 instead of Dockerfile in OpenShift?


Solution

  • TL;DR: Yes. You will not be able to use a Dockerfile with a different name than Dockerfile

    On Build Strategy Options on section Dockerfile Path you will find the constrains of OCP regarding the Docker Strategy:

    By default, Docker builds use a Dockerfile (named Dockerfile) located at the root of the context specified in the BuildConfig.spec.source.contextDir field.

    The dockerfilePath field allows the build to use a different path to locate your Dockerfile, relative to the BuildConfig.spec.source.contextDir field. It can be simply a different file name other than the default Dockerfile (for example, MyDockerfile), or a path to a Dockerfile in a subdirectory (for example, dockerfiles/app1/Dockerfile).

    And they also use an expample:

    strategy:
      dockerStrategy:
        dockerfilePath: dockerfiles/app1/Dockerfile