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
gcr.io/sneppets-gcp/hellodocker-image   latest              ef132619c2ac        3 weeks ago         5.55MB
gcr.io/sneppets-gcp/quickstart-image    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

$ docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]

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 gcr.io/sneppets-gcp/hellodocker-image 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
helloDockerQuickStart.sh  mnt                       run                       tmp

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

/ # vi helloDockerQuickStart.sh
#!/bin/sh
echo "Hello World!"
~
~
~
~
~
~
- helloDockerQuickStart.sh 2/2 100%

Further Learning

References

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments