Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

ubuntu - How to use multiple base images to build a docker image

I have used a base docker image (openjdk) to create an image having a simple Java Programme.

But I was wondering if I use 2 base images in a docker file. How can we do that? I don't think docker supports anything like:

FROM dockerImaage1
FROM dockerImage2

One of the scenarios, why this is required is I want an image of ubuntu having openjdk, so one way is I use the base image of ubuntu and the in docker file write instruction to install openjdk, set JAVA_HOME variable etc, which is undoubtedly cumbersome.

Another alternative, I like is using the base image of openjdk inside base of ubuntu (if possible).

There may be more typical cases, where we may need is feature damn badly.

SO any ideas on how to use 2 base images in a docker file? Has anyone done that yet?

I found a link of reverse engineering here, but it has some limitations like if the docker file of ubuntu uses commands like ADD or COPY, the reverse engineering fails.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The latest version of docker has the concept of multi stage builds. Refer: (https://docs.docker.com/engine/userguide/eng-image/multistage-build/)

With multi-stage builds, you use multiple FROM statements in your Dockerfile. Each FROM instruction can use a different base, and each of them begins a new stage of the build. You can selectively copy artifacts from one stage to another, leaving behind everything you don’t want in the final image.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...