Answers: <p>Using buildkit, you can mount from the build context with <code>type=bind</code> to access files without including them in your resulting image.</p>
  <pre><code># syntax=docker/dockerfile:1.3
  FROM base
  RUN --mount=type=bind,source=./rpms/,target=/rpms/ \
      yum install /rpms/package.rpm
  </code></pre>
  <p>See <a href="https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/syntax.md#run---mounttypebind-the-default-mount-type" rel="nofollow noreferrer">the buildkit docs</a> for more details.</p>
  
Answers: CC BY-SA 4.0
Answers: 2022-02-25T12:18:25.500Z
Answers: 2022-02-25T12:18:25.500Z
Answers: BMitch
Body: <p>During dockerbuild, I'd like to install a (rather big) RPM from build context/host without copying it first into the image in order to keep my image small.
  Ideally, there would be a way to read a file directly from build context.</p>
  <p>What are my options (beside using a HTTP server on the host)?
  What are the best practices for this use-case?</p>
  
Comments: CC BY-SA 4.0
Comments: 2022-02-25T09:29:01.173Z
Comments: Do you just want a file from the RPM?
Comments: mikequentel
Comments: CC BY-SA 4.0
Comments: 2022-02-28T12:33:45.917Z
Comments: @mikequentel Nope, I'd like to install the RPM.
Comments: MRalwasser
Tags: <docker><dockerfile><images>
Title: Install a RPM from build context without copying it first
UserDisplayName: MRalwasser
ThreadText: # Install a RPM from build context without copying it first
  
  (Asked by: username_0 on 2022-02-24)
  
  During dockerbuild, I'd like to install a (rather big) RPM from build context/host without copying it first into the image in order to keep my image small.
  Ideally, there would be a way to read a file directly from build context.
  
  What are my options (beside using a HTTP server on the host)?
  What are the best practices for this use-case?
  
  **Tags:** docker, dockerfile, images
  
  > **Comments:**
  > **username_1**: Do you just want a file from the RPM?  
  > **username_0**: @username_1 Nope, I'd like to install the RPM.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2022-02-25. Score: 3 | Accepted answer
  
  Using buildkit, you can mount from the build context with `type=bind` to access files without including them in your resulting image.
  
  ```
  # syntax=docker/dockerfile:1.3
  FROM base
  RUN --mount=type=bind,source=./rpms/,target=/rpms/ \
      yum install /rpms/package.rpm
  
  ```
  
  See [the buildkit docs](https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/syntax.md#run---mounttypebind-the-default-mount-type) for more details.
  
  
  ---
  
  