<p>What you need is to use the build pattern or the multistage features of docker</p>

<p><a href="https://docs.docker.com/develop/develop-images/multistage-build/" rel="nofollow noreferrer">https://docs.docker.com/develop/develop-images/multistage-build/</a></p>

<p>With that, you can use as many images as you need depending on your build process</p>

CC BY-SA 4.0
2019-06-15T14:31:12.557Z
Ok. Thanks! I will go with [an external image as stage](https://docs.docker.com/develop/develop-images/multistage-build/#use-an-external-image-as-a-stage) `COPY --from=A:latest path/to/image/jarfile destination`. Then omitting the FROM * AS statement.
0x00F
CC BY-SA 4.0
2019-06-12T14:31:25.830Z
2019-06-12T14:31:25.830Z
wolmi
<h1>Problem</h1>

<p>I have two repositories A and B. I have a docker image registry, where I can push the docker images made of the repositories A and B.</p>

<p>I need only the binary of A's source code to be included in the docker image of B. So when running the docker image of B, the jar file of A is present and can be used. And in case of updates in repository A, the registry image is subsequently updated.</p>

<h1>Question</h1>

<p>I've searched now several threads and the docker documentation. Is there a recommended way to make this happen with docker respectivly dockerfile commands?</p>

<p>So far I tried the following and it worked, but it wasn't so intiutive. Is this the recommended way?</p>

<pre><code>FROM myregistry/my-A-img AS A
FROM ubuntu-base-img

# Build commands for B ...
COPY build-B.jar /app

# Get the A image from the registry
COPY --from=A /path/to/build-A.jar /app/lib

# Run B binaries
</code></pre>

<docker><dockerfile>
Using the built binary of a docker image in another docker image
0x00F
# Using the built binary of a docker image in another docker image

(Asked by: username_0 on 2019-06-12)

Problem
I have two repositories A and B. I have a docker image registry, where I can push the docker images made of the repositories A and B.
I need only the binary of A's source code to be included in the docker image of B. So when running the docker image of B, the jar file of A is present and can be used. And in case of updates in repository A, the registry image is subsequently updated.
Question
I've searched now several threads and the docker documentation. Is there a recommended way to make this happen with docker respectivly dockerfile commands?
So far I tried the following and it worked, but it wasn't so intiutive. Is this the recommended way?
FROM myregistry/my-A-img AS A
FROM ubuntu-base-img

# Build commands for B ...
COPY build-B.jar /app

# Get the A image from the registry
COPY --from=A /path/to/build-A.jar /app/lib

# Run B binaries

**Tags:** docker, dockerfile


---

## 1 answers

### Answer by username_1 on 2019-06-12. Score: 0 | Accepted answer

What you need is to use the build pattern or the multistage features of docker

<https://docs.docker.com/develop/develop-images/multistage-build/>

With that, you can use as many images as you need depending on your build process

> **Comments:**
> **username_0**: Ok. Thanks! I will go with [an external image as stage](https://docs.docker.com/develop/develop-images/multistage-build/#use-an-external-image-as-a-stage) `COPY --from=A:latest path/to/image/jarfile destination`. Then omitting the FROM * AS statement.  

---

