Skip to main content
Skip table of contents

Step 2 of 4: Docker Images


In this step, you will search for, pull and import a few publicly available Docker images. You will also experiment with running a few simple commands on these images.

Pull an image

One of the features of Docker is that a lot of people have created Docker images for a variety of purposes. Many of these have been uploaded to Docker Hub, which is a publicly available registry where docker users can push their images and pull down the images others have made. We will pull down the Busybox image, which is a small linux distribution. You can download it using the docker pull command.

xnat@xnat-31:~$ docker pull busybox

This will find and download the busybox image from Docker Hub. You can now use this image by running a container.

xnat@xnat-31:~$ docker run -t busybox ls /bin
[                  freeramdisk        mkfifo             sha512sum
[[                 fsck               mkfs.ext2          showkey
acpid              fsck.minix         mkfs.minix         shuf
add-shell          fstrim             mkfs.vfat          slattach
addgroup           fsync              mknod              sleep
<output snipped>
find               mesg               setuidgid          yes
findfs             microcom           sh                 zcat
flock              mkdir              sha1sum            zcip
fold               mkdosfs            sha256sum
free               mke2fs             sha3sum


In this example:

  • docker run runs a container.
  • busybox is the image you would like to run.
  • -t flag assigns a pseudo-tty or terminal inside the new container.
  • The command /ls bin lists the contents of the /bin directory inside our container. 


We can see that the ls /bin command we just ran executed inside a container. That means that, essentially, a lightweight virtual machine based on the busybox image was started up just for our command to run, then shut down again when the command finished. This all happened in a fraction of a second, which is orders of magnitude faster than typical VMs. We can verify that the contents of the /bin directory on our XNAT VM are different from the contents of the container we just ran.

xnat@xnat-31:~$ ls /bin
bash			      	dir	     		loadkeys	       	ntfsfix				ss
bunzip2		      		dmesg	     	login	       		ntfsinfo			static-sh
busybox		      		dnsdomainname  	loginctl	       	ntfsls				stty
bzcat		      		domainname     	lowntfs-3g        	ntfsmftalloc		su
bzcmp		      		dumpkeys	    ls		       		ntfsmove			sync
bzdiff		      		echo	     	lsblk	       		ntfstruncate		tailf
<output snipped>
dbus-cleanup-sockets  	lessecho	    ntfscat	       		setfont				zgrep
dbus-daemon	      		lessfile	    ntfsck	       		setupcon			zless
dbus-uuidgen	      	lesskey	     	ntfscluster       	sh					zmore
dd		      			lesspipe	    ntfscmp	       		sh.distrib			znew
df		      			ln	     		ntfsdump_logfile  	sleep

The contents of /bin are completely different from what we saw inside the busybox container. 


The important concepts to take away from this are:

  • Commands we run "inside a container" can be run identically from any machine. They will all see absolutely nothing about the machine running docker; the commands only see the container, which is based on a docker image, which is the same everywhere.
  • Containers can be created from images almost instantaneously. This is different from virtual machines, which take a long time to copy and run.

Import Local Image Tar Archive

Although it is convenient to store and pull your images to a Docker repository like Docker Hub, in some instances you may wish save images to (and load images from) a local file.  We will use the docker load command to stream data from a prepackaged tar file located on your Vagrant VM.

xnat@xnat-31:~$ docker load -i /resources/docker/docker_ubuntu_latest.tar
9436069b92a3: Loading layer 127.6 MB/127.6 MB
19429b698a22: Loading layer 14.85 kB/14.85 kB
82b57dbc5385: Loading layer 11.78 kB/11.78 kB
737f40e80b7f: Loading layer 4.608 kB/4.608 kB
5f70bf18a086: Loading layer 1.024 kB/1.024 kB

In this example:

  • docker load loads an image from a tar file
  • -i is used to specify an input file, instead of STDIN
  • ubuntu.tar is a (provided) file that we generated for you using docker save

View Installed Images

We now have several images installed on our Docker server.  View a list of these images.

xnat@xnat-31:~$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ubuntu              latest              2fa927b5cdd3        9 days ago          122 MB
busybox             latest              47bcc53f74dc        11 weeks ago        1.113 MB


Next we will see some more things you can do to run and manage docker containers.


JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.