docker: how to show the diffs between 2 images

后端 未结 8 914
走了就别回头了
走了就别回头了 2021-01-30 10:33

I have a Dockerfile with a sequence of RUN instructions that execute \"apt-get install\"s; for example, a couple of lines:

RUN apt-get install -y tree
RUN apt-ge         


        
8条回答
  •  孤独总比滥情好
    2021-01-30 10:52

    If you know container ID or name (even stopped container), you can quickly dump file list on-the-fly.

    $ docker export CONTAIN_ID_OR_NAME | tar tv
    -rwxr-xr-x  0 0      0           0  2  6 21:22 .dockerenv
    -rwxr-xr-x  0 0      0           0  2  6 21:22 .dockerinit
    drwxr-xr-x  0 0      0           0 10 21 13:46 bin/
    -rwxr-xr-x  0 0      0     1021112 10  8  2014 bin/bash
    -rwxr-xr-x  0 0      0       31152 10 21  2013 bin/bunzip2
    -rwxr-xr-x  0 0      0           0 10 21  2013 bin/bzcat link to bin/bunzip2
    lrwxrwxrwx  0 0      0           0 10 21  2013 bin/bzcmp -> bzdiff
    -rwxr-xr-x  0 0      0        2140 10 21  2013 bin/bzdiff
    lrwxrwxrwx  0 0      0           0 10 21  2013 bin/bzegrep -> bzgrep
    -rwxr-xr-x  0 0      0        4877 10 21  2013 bin/bzexe
    ......
    

    Then you can save list to file and compare too list files.

    If you insist to use image ID or name, you can dump first layer's file list on-the-fly:

    $ docker save alpine |tar xO '*/layer.tar' | tar tv
    drwxr-xr-x  0 0      0           0 12 27 06:32 bin/
    lrwxrwxrwx  0 0      0           0 12 27 06:32 bin/ash -> /bin/busybox
    lrwxrwxrwx  0 0      0           0 12 27 06:32 bin/base64 -> /bin/busybox
    lrwxrwxrwx  0 0      0           0 12 27 06:32 bin/bbconfig -> /bin/busybox
    -rwxr-xr-x  0 0      0      821408 10 27 01:15 bin/busybox
    

    After all, i suggest you start the container then stop it, then you can get a merged file list as described in first way.

    2017/02/01: The fastest way to show container's file list, you are free to enter its root dir to read files:

    # PID=$(docker inspect -f '{{.State.Pid}}' CONTAIN_ID_OR_NAME)
    # cd /proc/$PID/root && ls -lF
    drwxr-xr-x  0 0      0           0 12 27 06:32 bin/
    lrwxrwxrwx  0 0      0           0 12 27 06:32 bin/ash -> /bin/busybox
    lrwxrwxrwx  0 0      0           0 12 27 06:32 bin/base64 -> /bin/busybox
    lrwxrwxrwx  0 0      0           0 12 27 06:32 bin/bbconfig -> /bin/busybox
    -rwxr-xr-x  0 0      0      821408 10 27 01:15 bin/busybox
    

    Note, if you are using docker-machine, you need first enter it by docker-machine ssh then sudo sh.

    Now you get the root dir of the two container, you can use diff to compare them directly.

提交回复
热议问题