Does Docker EXPOSE make a new layer?

后端 未结 4 1704
时光说笑
时光说笑 2021-02-14 17:07

I have been playing around with creating docker files and reading the documentation and I was wondering this question: Does adding an EXPOSE command to my Doc

4条回答
  •  我在风中等你
    2021-02-14 17:28

    Yes, every instruction in a Dockerfile generates a new layer for the resulting image.

    However, layers created via EXPOSE are empty layers. That is, their size is 0 bytes.

    While they don't impact you storage-wise, they do count for leveraging layer cache while building or pulling/pushing images from a registry.

    A good way to understand an image's layers is to use the docker history command. For instance, given the following Dockerfile:

    FROM scratch
    
    EXPOSE 4000
    EXPOSE 3000
    

    do

    docker build -t test/image .

    If you then docker history test/image you'll see:

    IMAGE               CREATED             CREATED BY                           SIZE                COMMENT
    ab9f435de7bc        4 seconds ago       /bin/sh -c #(nop)  EXPOSE 4000/tcp   0 B                 
    15e09691c313        5 seconds ago       /bin/sh -c #(nop)  EXPOSE 3000/tcp   0 B     
    

    If you switch the order of the EXPOSE statements and build again, you'll see the layer cache being ignored.

提交回复
热议问题