How to see docker image contents

前端 未结 9 1199
说谎
说谎 2020-11-30 16:18

I did a docker pull and can list the image that\'s downloaded. I want to see the contents of this image. Did a search on the net but no straight answer.

9条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-30 16:53

    The accepted answer here is problematic, because there is no guarantee that an image will have any sort of interactive shell. For example, the drone/drone image contains on a single command /drone, and it has an ENTRYPOINT as well, so this will fail:

    $ docker run -it drone/drone sh
    FATA[0000] DRONE_HOST is not properly configured        
    

    And this will fail:

    $ docker run --rm -it --entrypoint sh drone/drone
    docker: Error response from daemon: oci runtime error: container_linux.go:247: starting container process caused "exec: \"sh\": executable file not found in $PATH".
    

    This is not an uncommon configuration; many minimal images contain only the binaries necessary to support the target service. Fortunately, there are mechanisms for exploring an image filesystem that do not depend on the contents of the image. The easiest is probably the docker export command, which will export a container filesystem as a tar archive. So, start a container (it does not matter if it fails or not):

    $ docker run -it drone/drone sh
    FATA[0000] DRONE_HOST is not properly configured        
    

    Then use docker export to export the filesystem to tar:

    $ docker export $(docker ps -lq) | tar tf -
    

    The docker ps -lq there means "give me the id of the most recent docker container". You could replace that with an explicit container name or id.

提交回复
热议问题