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

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

问题描述



如下所示:

  genericA  -  
\
---> specificAB
/
genericB -

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



我想要使用Java MySQL的图片。

解决方案

Docker不直接支持此功能,但您可以使用 Docker Make (完整的说明:我写了)来管理这种继承。它使用YAML文件来设置图像的各个部分,然后通过生成适当的Dockerfiles来驱动构建。



以下是如何构建这个稍微更复杂的示例:

   - > genericA  -  
/ \
phusion / baseimage - > customBase ---> specificAB
\ /
- > genericB -

您将使用这个 DockerMake.yaml file:

  specificAB:
要求:
- genericA
- genericB

genericA:
要求:
- customBase
build_directory:[一些本地目录]
build:|
#Docker构建命令去这里,如
ADD installA.sh
RUN ./installA.sh

genericB:
要求:
- customBase
build:|
#还有一些其他可以运行的命令
RUN apt-get install -y genericB
ENV PATH = $ PATH:something

customBase:
FROM:phusion / baseimage
build:|
RUN apt-get update&& apt-get install -y buildessentials

您将构建 specificAB image只需运行

  docker-make.py specificAB 


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

Like this here:

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

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

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

解决方案

Docker doesn't directly support this, but you can use Docker Make (full discloure: I wrote it) to manage this sort of "inheritance". It uses YAML file to set up the individual pieces of the image, then drives the build by generating the appropriate Dockerfiles.

Here's how you would build this slightly more complicated example:

                                     --> genericA --
                                    /                \
   phusion/baseimage -->  customBase                   ---> specificAB
                                    \                /
                                      --> genericB --

You would use this DockerMake.yaml file:

specificAB:
  requires:
    - genericA
    - genericB

genericA:
  requires:
     - customBase
  build_directory: [some local directory]
  build: |
    #Docker build commands go here, such as
    ADD installA.sh
    RUN ./installA.sh

genericB:
  requires:
    - customBase
  build: |
    #Here are some other commands you could run
    RUN apt-get install -y genericB
    ENV PATH=$PATH:something

customBase:
  FROM: phusion/baseimage
  build: |
    RUN apt-get update && apt-get install -y buildessentials

You would build the specificAB image just by running

docker-make.py specificAB

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

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