0

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
0

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

1
  • Ok. Thanks! I will go with an external image as stage COPY --from=A:latest path/to/image/jarfile destination. Then omitting the FROM * AS statement. – 0x00F Jun 15 '19 at 14:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.