Docker:组合多个图像 [英] Docker: Combine multiple images

查看:33
本文介绍了Docker:组合多个图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Docker 是否可以将两个图像合二为一?

Is it possible with Docker to combine two images into one?

像这里:

genericA --
            \
             ---> specificAB
            /
genericB --

例如,有一个用于 Java 的图像和一个用于 MySQL 的图像.

For example there's an image for Java and an image for MySQL.

我想要一个带有 Java MySQL 的图像.

I'd like to have an image with Java and MySQL.

推荐答案

不,您只能从一个图像继承.

No, you can only inherit from one image.

您可能不希望 Java 和 MySQL 位于同一个映像中,因为在容器中包含单个组件更为惯用,即创建一个单独的 MySQL 容器并将其链接到 Java 容器,而不是将两者放在同一个容器中.

You probably don't want Java and MySQL in the same image as it's more idiomatic to have a single component in a container i.e. create a separate MySQL container and link it to the Java container rather than put both into the same container.

但是,如果您确实必须将它们放在同一个映像中,请使用 Java 作为基础映像(FROM 语句)编写一个 Dockerfile,并在 Dockerfile 中安装 MySQL.您应该能够从官方 MySQL Dockerfile 中大量复制语句.

However, if you really must have them in the same image, write a Dockerfile with Java as the base image (FROM statement) and install MySQL in the Dockerfile. You should be able to largely copy the statements from the official MySQL Dockerfile.

这篇关于Docker:组合多个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆