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

CC BY-SA 4.0
2022-02-25T12:18:25.500Z
2022-02-25T12:18:25.500Z
BMitch
<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>

CC BY-SA 4.0
2022-02-25T09:29:01.173Z
Do you just want a file from the RPM?
mikequentel
CC BY-SA 4.0
2022-02-28T12:33:45.917Z
@mikequentel Nope, I'd like to install the RPM.
MRalwasser
<docker><dockerfile><images>
Install a RPM from build context without copying it first
MRalwasser
# 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 for more details.


---

