Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-29085

Allow to use the docker build --file option when building an image


    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • Jenkins 1.6.10
      CloudBees Docker Build and Publish plugin version 1.0
      Ubuntu 14.04

      Allow to use the docker build --file option when building an image

      We would like to NOT have the Dockerfile at the root of the project, and have everything docker related in a subfolder "docker".

      Then we would build the image with
      docker build -t myrepo/myproject:v01 --file docker/Dockerfile .
      '.' is the docker context, meaning even though the Dockerfile is in a subfolder 'docker', docker can still access everything under '.' (the root of the project).
      It is not possible otherwise to access folders outside of the context, in a Dockerfile (using
      ADD../src/myfile.jar /srv/lib/myfile.jar
      ,for example. '..' is not allowed).

      So it would be nice to still have the options, in the GUI:

      • "Directory Dockerfile is in" (equivalent of "--file <path>)
      • "Docker context".

      In the code, this seems to be in function buildAndTag() in file:


      {{String context = defined(getDockerfilePath()) ?
      getDockerfilePath() : ".";

      lastResult = executeCmd("docker build -t " + i.next()
      + ((isNoCache()) ? " --no-cache=true " : "") + " "
      + ((isForcePull()) ? " --pull=true " : "") + " "
      + context);}}

      The line
      {{String context = defined(getDockerfilePath()) }}
      should be changed so that DockerfilePath is not the same as context. Those should be different things.

            csanchez Carlos Sanchez
            qnerden Quentin Nerden
            2 Vote for this issue
            4 Start watching this issue