How to check docker image contents after you pull a docker image

Do you want to check docker image contents after you pull a docker image, then you need to run interactive shell using docker run command.

For instance, let us say you had pulled hellodocker-image as shown below

sneppets@cloudshell:~ (sneppets-gcp)$ docker images -a
REPOSITORY                              TAG                 IMAGE ID            CREATED             SIZE   latest              ef132619c2ac        3 weeks ago         5.55MB    latest              172c907199d3        3 weeks ago         5.55MB

Check docker image contents – docker run command

Now let’s see how to check hellodocker-image contents or files using interactive shell. The basic docker run command is as shown below


The following are the OPTIONS that you can use for docker run command

-a=[]           : Attach to `STDIN`, `STDOUT` and/or `STDERR`
-t              : Allocate a pseudo-tty
--sig-proxy=true: Proxy all received signals to the process (non-TTY mode only)
-i              : Keep STDIN open even if not attached

For interactive shell you must use -i and -t together to allocate a tty for the container process. Note, tty is a command in Unix and Unix-like operating systems to print the file name of the terminal connected to standard input. And -i and -t if often written as -it as shown in example below.

$ docker run -it <docker image> sh

sneppets@cloudshell:~ (sneppets-gcp)$ docker run -it sh
/ # 

Using -it option in the above docker run command you got the interactive shell prompt. Now, you can give linux “ls” command to check the contents of the docker image as shown below

/ # ls
bin                       home                      opt                       sbin                      usr
dev                       lib                       proc                      srv                       var
etc                       media                     root                      sys  mnt                       run                       tmp

This hellodocker-image image has a file called You can use vi command to view the contents of that file

/ # vi
echo "Hello World!"
- 2/2 100%

Further Learning


Notify of

Inline Feedbacks
View all comments