Docker: Combine multiple images

前端 未结 4 1133
春和景丽
春和景丽 2020-11-27 18:27

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

Like this here:

genericA --
            \\
             ---> specificAB
            /
g         


        
4条回答
  •  我在风中等你
    2020-11-27 19:17

    Docker doesn't directly support this, but you can use DockerMake (full disclosure: I wrote it) to manage this sort of "inheritance". It uses a 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 --
                                        /                \
          debian:jessie -->  customBase                   ---> specificAB
                                        \                /
                                          --> genericB --
    

    You would use this DockerMake.yml file:

    specificAB:
      requires:
        - genericA
        - genericB
    
    genericA:
      requires:
         - customBase
      build_directory: [some local directory]
      build: |
        #Dockerfile 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: debian:jessie
      build: |
        RUN apt-get update && apt-get install -y buildessentials
    

    After installing the docker-make CLI tool (pip install dockermake), you can then build the specificAB image just by running

    docker-make specificAB
    

提交回复
热议问题