Docker

Getting Started with Docker: Docker Images

Docker is a set of platform as a service (PaaS) products that use OS-level virtualization to deliver software in packages called containers.

Docker containers are built from Docker images. These images are retrieved from Docker Hub, a registry managed by the Docker project. You can host Docker images on the Hub. It’s the most popular place to grab images with more than 100,000 container images.

However, a huge number of these images are unmaintained, so you need to be selective about which images to explore.

Run a Docker Image

Let’s test that our Docker installation can retrieve images from Docker Hub. At the command line type:

$ docker run hello-world

By default, a docker installation doesn’t have any images stored locally. The docker command is therefore unable to find the hello-world image locally when we try to run the image. The program contacts Docker Hub and downloads the hello-world image. It then proceeds to create a container from the image, and run the application stored in the container, with the output shown below.

sde@ganges:~$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete 
Digest: sha256:37a0b92b08d4919615c3ee023f7ddb068d12b8387475d64c622ac30f45c29c51
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

If you want only to download a Docker image replace the run command with pull. As you can see, docker reports that our hello-world image is up to date.

sde@ganges:~$ docker pull hello-world
Using default tag: latest
latest: Pulling from library/hello-world
Digest: sha256:37a0b92b08d4919615c3ee023f7ddb068d12b8387475d64c622ac30f45c29c51
Status: Image is up to date for hello-world:latest
docker.io/library/hello-world:latest

List installed images

Listing the installed images is simple. At the command line type:

$ docker images

sde@ganges:~$ docker images
REPOSITORY    TAG       IMAGE ID       CREATED       SIZE
hello-world   latest    feb5d9fea6a5   6 weeks ago   13.3kB

List containers

At the command line, type:

$ docker ps -a

sde@ganges:~$ docker ps -a 
CONTAINER ID   IMAGE         COMMAND    CREATED        STATUS                    PORTS     NAMES
808ccbb253c8   hello-world   "/hello"   14 hours ago   Exited (0) 14 hours ago             blissful_goodall

If we omit the -a option the command only shows containers that are running.


Remove an installed image

Let’s suppose we want to remove the hello-world container. At the command line, type:

$ docker rmi -f hello-world

The -f option forces the removal of the image.


Search for Images

We can use the command search to look for matches on Docker Hub. For example, if we want to search for Nextcloud (a suite of client-server software for creating and using file hosting service), we type:

$ docker search nextcloud

When experimenting with docker images, we recommend you start with matches that have [OK] in the OFFICIAL column. The vast majority of docker images stored on Docker Hub are unmaintained.


All articles in this series:

Getting Started with Docker
Installing Docker EngineLet's start with the basics. We install Docker Engine on Ubuntu
Run Docker without sudoRun Docker without the security privileges of root
CommandsA brief overview of the 40 Docker commands
ImagesA Docker image is a file used to execute code in a Docker container
Portainer CEInstall this interface to manage different Docker environments
DryInteractive CLI for Docker containers
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Please read our FAQ before making a comment.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments