what are the advantages of having layers in a dock

2019-07-10 05:45发布

问题:

Let's say I have two different Dockerfiles.

  1. Image one called nudoc/my-base-image:1.1

    FROM ubuntu:16.10
    COPY . /test.war
    
  2. Image two called nudoc/my-testrun-image:1.1

     FROM acme/my-base-image:1.1
     CMD /test/start.sh
    

Both have the layers in common.
What are the advantages of having layers in a docker image? does it benefit from pulling from the registry?

回答1:

As Henry already stated

Common layers are downloaded only once and are stored only once. So this has benefits for download as well as storage.

Additionaly building an image will reuse layers if the creating command allows. This reduces the build time. For example if you copy a file into your image and the file is the same as in the last build the old layer will be reused. See the best practices for writing dockerfiles for more details.



回答2:

Common layers are downloaded only once and are stored only once. So this has benefits for download as well as storage.



回答3:

A layer will be downloaded once, and possibly reused for other images. You can see them as intermediate images, and those intermediate images are combined together to create a bigger one. In continuous integration, this can save quite some time !

I suggest you read the official documentation page: https://docs.docker.com/engine/userguide/storagedriver/imagesandcontainers/



回答4:

Docker uses aufs file system as default where each instruction defined in your Dockerfile will acts as a each individual layer, if you add or update an instruction it will effect the respective layer hence it helps you to build, reuse or update your Docker image instantly, to learn more about layers and image read here



标签: docker