what are the advantages of having layers in a dock

2019-07-10 05:32发布

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?

标签: docker
4条回答
别忘想泡老子
2楼-- · 2019-07-10 05:41

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.

查看更多
放我归山
3楼-- · 2019-07-10 05:42

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/

查看更多
Juvenile、少年°
4楼-- · 2019-07-10 05:49

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

查看更多
Summer. ? 凉城
5楼-- · 2019-07-10 05:54

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

查看更多
登录 后发表回答