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.
1 2 3 4 |
~$ sudo docker images [sudo] password for falcon: REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest 48b5124b2768 4 months ago 1.84 kB |
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)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
$ sudo docker search ubuntu [sudo] password for falcon: NAME DESCRIPTION STARS OFFICIAL AUTOMATED ubuntu Ubuntu is a Debian-based Linux operating s... 6104 [OK] rastasheep/ubuntu-sshd Dockerized SSH service, built on top of of... 89 [OK] ubuntu-upstart Upstart is an event-based replacement for ... 74 [OK] ubuntu-debootstrap debootstrap --variant=minbase --components... 30 [OK] torusware/speedus-ubuntu Always updated official Ubuntu docker imag... 28 [OK] nuagebec/ubuntu Simple always updated Ubuntu docker images... 21 [OK] nickistre/ubuntu-lamp LAMP server on Ubuntu 19 [OK] solita/ubuntu-systemd Ubuntu + systemd 8 [OK] nimmis/ubuntu This is a docker images different LTS vers... 7 [OK] darksheer/ubuntu Base Ubuntu Image -- Updated hourly 3 [OK] jordi/ubuntu Ubuntu Base Image 1 [OK] webhippie/ubuntu Docker images for ubuntu 1 [OK] vcatechnology/ubuntu A Ubuntu image that is updated daily 1 [OK] admiringworm/ubuntu Base ubuntu images based on the official u... 1 [OK] labengine/ubuntu Images base ubuntu 0 [OK] konstruktoid/ubuntu Ubuntu base image 0 [OK] datenbetrieb/ubuntu custom flavor of the official ubuntu base ... 0 [OK] forumi0721ubuntux64/ubuntu-x64-dev ubuntu-x64-dev 0 [OK] lynxtp/ubuntu https://github.com/lynxtp/docker-ubuntu 0 [OK] forumi0721ubuntuarmhf/ubuntu-armhf-dev ubuntu-armhf-dev 0 [OK] forumi0721ubuntuaarch64/ubuntu-aarch64-dev ubuntu-aarch64-dev 0 [OK] teamrock/ubuntu TeamRock's Ubuntu image configured with AW... 0 [OK] smartentry/ubuntu ubuntu with smartentry 0 [OK] esycat/ubuntu Ubuntu LTS 0 [OK] forumi0721ubuntux64/ubuntu-x64-dev-armbian ubuntu-x64-dev-armbian 0 [OK] falcon@falcon-Satellite-L50D-B:~$ |
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.
1 2 3 4 5 6 7 8 9 10 11 12 |
~$ sudo docker pull nimmis/ubuntu Using default tag: latest latest: Pulling from nimmis/ubuntu bd97b43c27e3: Pull complete 6960dc1aba18: Pull complete 2b61829b0db5: Pull complete 1f88dc826b14: Pull complete 73b3859b1e43: Pull complete 06256784393b: Pull complete 8b3f317c599d: Pull complete Digest: sha256:5607642f02113fa3247290ade1b397892a07aab52e27babb5a436752c5c21a19 Status: Downloaded newer image for nimmis/ubuntu:latest |
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:
1 |
$ sudo docker run –i –t nginx:latest /bin/bash |
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>
1 |
$ sudo docker run -d -p 8080:80 ubuntu:14.10 |
In the next part of this series we will discuss about how to manipulate Docker images in detail.