Answers: <pre><code>node {
  checkout scm 
  app = docker.build("test-image","-f path/to/dockerfile .")
  }
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2019-03-13T22:54:51.930Z
Answers: 2019-03-13T22:54:51.930Z
Answers: VinDev
Answers: <p>From the <a href="https://jenkins.io/doc/book/pipeline/docker/#building-containers" rel="nofollow noreferrer">official instructions on building Docker images with Jenkins Pipeline</a>:</p>
  
  <blockquote>
    <p>The <code>build()</code> method builds the <code>Dockerfile</code> in the current directory
    by default. This can be overridden by providing a directory path
    containing a <code>Dockerfile</code> as the second argument of the <code>build()</code>
    method, for example:</p>
  
  <pre><code>node {
      checkout scm
      def testImage = docker.build("test-image", "./dockerfiles/test") 
  
      testImage.inside {
          sh 'make test'
      }
  }
  </code></pre>
  </blockquote>
  
  <p>I'm not sure if you can create a Pipeline (i.e. Jenkinsfile) with this exact configuration through the Blue Ocean UI, but I would imagine you can.  However, I personally have found using Blue Ocean to create pipelines to be finicky at best, so I would recommend going over a Jenkinsfile created by Blue Ocean and making tweaks and adjustments by hand anyway.  This would give you the opportunity to adjust the Dockerfile location even if you aren't able to do it via Blue Ocean.</p>
  
Answers: CC BY-SA 4.0
Answers: 2019-03-09T07:35:35.267Z
Answers: 2019-03-09T07:35:35.267Z
Answers: jayhendren
Body: <p>I want my pipeline created using Blue Ocean (Jenkins) to build with a dockerfile that is not in the root of the git repo. How do I achieve this?</p>
  
  <p>Our git repo is a collection of sub-projects with each containing it's own dockerfile. So we cannot place them in the root directory.</p>
  
Tags: <docker><jenkins><dockerfile><jenkins-blueocean>
Title: How do i specify the path of a Dockerfile using Blue Ocean
UserDisplayName: Brendan Miller
ThreadText: # How do i specify the path of a Dockerfile using Blue Ocean
  
  (Asked by: username_0 on 2019-03-07)
  
  I want my pipeline created using Blue Ocean (Jenkins) to build with a dockerfile that is not in the root of the git repo. How do I achieve this?
  
  Our git repo is a collection of sub-projects with each containing it's own dockerfile. So we cannot place them in the root directory.
  
  **Tags:** docker, jenkins, dockerfile, jenkins-blueocean
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2019-03-13. Score: 1
  
  ```
  node {
  checkout scm 
  app = docker.build("test-image","-f path/to/dockerfile .")
  }
  
  ```
  
  
  ---
  
  ### Answer by username_2 on 2019-03-09. Score: 1
  
  From the [official instructions on building Docker images with Jenkins Pipeline](https://jenkins.io/doc/book/pipeline/docker/#building-containers):
  
  > The `build()` method builds the `Dockerfile` in the current directory
  > by default. This can be overridden by providing a directory path
  > containing a `Dockerfile` as the second argument of the `build()`
  > method, for example:
  >
  > ```
  > node {
  >     checkout scm
  >     def testImage = docker.build("test-image", "./dockerfiles/test") 
  >
  >     testImage.inside {
  >         sh 'make test'
  >     }
  > }
  >
  > ```
  
  I'm not sure if you can create a Pipeline (i.e. Jenkinsfile) with this exact configuration through the Blue Ocean UI, but I would imagine you can. However, I personally have found using Blue Ocean to create pipelines to be finicky at best, so I would recommend going over a Jenkinsfile created by Blue Ocean and making tweaks and adjustments by hand anyway. This would give you the opportunity to adjust the Dockerfile location even if you aren't able to do it via Blue Ocean.
  
  
  ---
  
  