Docker : Brief Introduction – Part 2

Using Docker Images

We can find out which images are available at our environment using the command given below.

docker images

As Docker command requires root privilege, run it with sudo.

The columns of the output for docker images command are :

REPOSITORY – name of repository as existing in docker hub

TAG – tag of the image (could indicate different versions) – can help backwards compatibility testing of app

IMAGE ID – unique 64 hex digit string of chars – simplified to first 12 chars

CREATED – when created

SIZE – how much virtual size

 

Searching images at Docker Hub

We can look for available docker images at Docker Hub using the “docker search” command. (of course, start with sudo so as to run it with root privilege)

We can see the name of the repository, a reduced description, how many people have starred it as being something they think is a good repository, whether it’s an official repository (which means that it’s been approved by the Docker team), as well as whether it’s an automated build.

An automated build is a Docker image that builds automatically when a Git repository that it is linked to is updated. The code gets updated, a web hook gets called, and a new Docker image is built in the Docker Hub.

To pull an image from Docker Hub, use :

docker pull <image name>

Example:

docker pull tutum/ubuntu

After pulling, we can display the list of images that we have currently using “docker images” command.

Running the images

Let’s look at how to get images up and running and turned into containers.

The most basic way to run a container is as follows:

 docker run -i -t <image_name>:<tag> /bin/bash

Example:

We start off with the docker run command, followed by two options, -i and -t .

The first -i option, gives us an interactive shell into the running container. The second -t option will allocate a pseudo tty, which when using interactive processes, must be used together with the -i switch. You can also use switches together; for example, -it is commonly used for these two switches. This will help you test out the container to see how it operates before running it as a daemon.

Once you are comfortable with your container, you can test how it operates in daemon mode:

docker run -d <image_name>:<tag>

We can see the container ID, the image name on which the container is based, the command that is running to keep the image alive, when the container started up, its current status, a listing of any exposed network ports, as well as the name given to the container. Now, these names are random unless otherwise specified by the –name= switch.

You can also expose ports on your containers using the -p switch, just like this:

$ docker run -d -p <host_port>:<container_port> <image>:<tag>

In the next part of this series we will discuss about how to manipulate Docker images in detail.

 

Scroll to Top