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".

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

      src/main/java/com/cloudbees/dockerpublish/DockerBuilder.java

      {{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.

          [JENKINS-29085] Allow to use the docker build --file option when building an image

          Quentin Nerden created issue -
          Quentin Nerden made changes -
          Description Original: 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../scr/myfile.jar /srv/lib/}}
          ,for example. '..' is not allowed).

          So it would be nice to still have the option:
          - "Directory Dockerfile is in" (equivalent of "--file <path>)
          - "Docker context".




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

          {{src/main/java/com/cloudbees/dockerpublish/DockerBuilder.java}}

          {{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.
          New: 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../scr/myfile.jar /srv/lib/}}
          ,for example. '..' is not allowed).

          So it would be nice to still have the option:
          - "Directory Dockerfile is in" (equivalent of "--file <path>)
          - "Docker context".




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

          {{src/main/java/com/cloudbees/dockerpublish/DockerBuilder.java}}

          {{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.
          Quentin Nerden made changes -
          Description Original: 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../scr/myfile.jar /srv/lib/}}
          ,for example. '..' is not allowed).

          So it would be nice to still have the option:
          - "Directory Dockerfile is in" (equivalent of "--file <path>)
          - "Docker context".




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

          {{src/main/java/com/cloudbees/dockerpublish/DockerBuilder.java}}

          {{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.
          New: 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../scr/myfile.jar /srv/lib/}}
          ,for example. '..' is not allowed).

          So it would be nice to still have the option:
          - "Directory Dockerfile is in" (equivalent of "--file <path>)
          - "Docker context".




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

          {{src/main/java/com/cloudbees/dockerpublish/DockerBuilder.java}}

          {{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.
          Quentin Nerden made changes -
          Description Original: 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../scr/myfile.jar /srv/lib/}}
          ,for example. '..' is not allowed).

          So it would be nice to still have the option:
          - "Directory Dockerfile is in" (equivalent of "--file <path>)
          - "Docker context".




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

          {{src/main/java/com/cloudbees/dockerpublish/DockerBuilder.java}}

          {{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.
          New: 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../scr/myfile.jar /srv/lib/myfile.jar}}
          ,for example. '..' is not allowed).

          So it would be nice to still have the option:
          - "Directory Dockerfile is in" (equivalent of "--file <path>)
          - "Docker context".




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

          {{src/main/java/com/cloudbees/dockerpublish/DockerBuilder.java}}

          {{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.
          Quentin Nerden made changes -
          Description Original: 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../scr/myfile.jar /srv/lib/myfile.jar}}
          ,for example. '..' is not allowed).

          So it would be nice to still have the option:
          - "Directory Dockerfile is in" (equivalent of "--file <path>)
          - "Docker context".




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

          {{src/main/java/com/cloudbees/dockerpublish/DockerBuilder.java}}

          {{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.
          New: 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 option:
          - "Directory Dockerfile is in" (equivalent of "--file <path>)
          - "Docker context".




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

          {{src/main/java/com/cloudbees/dockerpublish/DockerBuilder.java}}

          {{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.
          Quentin Nerden made changes -
          Description Original: 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 option:
          - "Directory Dockerfile is in" (equivalent of "--file <path>)
          - "Docker context".




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

          {{src/main/java/com/cloudbees/dockerpublish/DockerBuilder.java}}

          {{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.
          New: 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".




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

          {{src/main/java/com/cloudbees/dockerpublish/DockerBuilder.java}}

          {{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.

          Looking at the screenshot under "How to use" in the jenkins wiki:
          https://wiki.jenkins-ci.org/display/JENKINS/CloudBees+Docker+Build+and+Publish+plugin
          shows a textbox called Build Context.
          This seems to be this feature.
          Was it part of the plugin and then removed?

          Quentin Nerden added a comment - Looking at the screenshot under "How to use" in the jenkins wiki: https://wiki.jenkins-ci.org/display/JENKINS/CloudBees+Docker+Build+and+Publish+plugin shows a textbox called Build Context. This seems to be this feature. Was it part of the plugin and then removed?

          Oded Arbel added a comment -

          That was already implemented. The text box is called "Dockerfile Path"

          Oded Arbel added a comment - That was already implemented. The text box is called "Dockerfile Path"
          R. Tyler Croy made changes -
          Workflow Original: JNJira [ 163953 ] New: JNJira + In-Review [ 181445 ]

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

              Created:
              Updated: