Image

TL;DR

Lifecycle

  • docker images shows all images.
  • docker import creates an image from a tarball.
  • docker build creates image from Dockerfile.
  • docker commit creates image from a container, pausing it temporarily if it is running.
  • docker rmi removes an image.
  • docker load loads an image from a tar archive as STDIN, including images and tags (as of 0.7).
  • docker save saves an image to a tar archive stream to STDOUT with all parent layers, tags & versions (as of 0.7).

Info

Cleaning up

  • docker image prune is also available for removing unused images. (See Prune).

Basic usages

In Docker, everything is based on Images. Images are templates for creating docker containers.

Listing images

docker images
REPOSITORY               TAG          IMAGE ID       CREATED         SIZE
docker-hello-world_web   latest       85f9e3024e99   14 hours ago    196MB
my_image                 0.0.1        9f3378bbf7e4   36 hours ago    133MB
nginx                    v3           6ed4b5e97df7   37 hours ago    133MB
python                   3.7-alpine   0ce5215b0b31   43 hours ago    41.1MB
nginx                    latest       7baf28ea91eb   2 days ago      133MB
ubuntu                   latest       f643c72bc252   2 weeks ago     72.9MB
  • REPOSITORY : repository source of image

  • TAG : tag of image

    • There could be a number of tags in the same repository source, representing different version of this repository source. For example, in ubuntu repository source, there are many different versions such as 15.10, 14.04, etc. We use REPOSITORY:TAG to specify different images

    • For example, if we want to run container with ubuntu version 15.10:

      docker run -t -i ubuntu:15.10 /bin/bash
      
  • IMAGE ID : ID of image

  • CREATED: creation time of image

  • SIZE : size of image

Downloading images

Docker automatically downloads a non-existent image when we use it on the local host. If we want to pre-download the image, we can use the docker pull command to download it.

For example, we download ubuntu:13.10, which doesn’t exist in the local machine:

docker pull ubuntu:13.10

Searching images

We can search images in Docker Hub.

Removing images

Removing image using image ID:

docker rmi <image-ID>

Removing image using image name

docker rmi <image-name>

Building image

We use the command docker build to create a new image from scratch. To do this, we need to create a Dockerfile file that contains a set of instructions to tell Docker how to build our image. (More see Dockerfile)

Tagging image

docker tag <image-ID> <image-tag>

Reference