docker: extracting a layer from a image

前端 未结 5 1480
既然无缘
既然无缘 2020-12-28 20:11

Let\'s take the whalesay images as an example. docker history shows the following:

IMAGE               CREATED             CREATED BY                    


        
5条回答
  •  轮回少年
    2020-12-28 21:15

    It looks like other people would also like to have this feature, but unfortunately right now it does not seem to exist.

    See also this issue and here a related request which got rejected.

    If you're fine with saving the complete docker (docker save) and then extracting a tarball with your layer, then this is possible:

    docker run -it 
    # do fancy stuff in the container
    docker commit  foobar # create image from container
    docker history foobar # will show you the layers
    docker save -o foobar.tar foobar # dumps container contents to foobar.tar
    

    Now foobar.tar will contain the file system states from different times. Inspecting this tarball shows, in my case, a file repositories with

    {"foobar":{"latest":"fdf43d96e691c57e9afb4b85dba2e6745146a7ca9076c7284c6b2e1f93434562"}}
    

    which indicates, that the latest layer is fdf43.... You can get a tarball with the file system contents of this layer via

    tar -x fdf43d96e691c57e9afb4b85dba2e6745146a7ca9076c7284c6b2e1f93434562/layer.tar -f foobar.tar
    

    There is a tool, undocker, which automated this process, but I'm not sure whether it will work with the current format of the saved tar file.

提交回复
热议问题