Docker Tutorial
Docker Installation
How to use Docker
Docker Instance
Docker Container Lifecycle Command
Docker Container Operation Command
Docker Container rootfs Command
Docker Mirror Repository Command
Docker Local Image Management Command
Docker info|version Command
The docker image
command is a management command for Docker images, providing various subcommands to list, remove, inspect, and perform other operations on images. This tutorial will guide you through the basics of using the docker image
command and its subcommands.
Prerequisites:
docker pull ubuntu:20.04
This command will download the ubuntu:20.04
image from Docker Hub.
List Docker images:
To display a list of Docker images on your system, run:
docker image ls
This will display a table with the same columns as the docker images
command: REPOSITORY
, TAG
, IMAGE ID
, CREATED
, and SIZE
.
Remove Docker images:
To remove an image from your system, use the docker image rm
or docker rmi
command:
docker image rm IMAGE
Replace IMAGE
with the image ID, repository name, or repository name with tag.
For example, to remove the ubuntu:20.04
image, use:
docker image rm ubuntu:20.04
Inspect Docker images:
To inspect an image and display its metadata and configuration in JSON format, use the docker image inspect
command:
docker image inspect IMAGE
Replace IMAGE
with the image ID, repository name, or repository name with tag.
For example, to inspect the ubuntu:20.04
image, use:
docker image inspect ubuntu:20.04
Display image history:
To display the history of an image, use the docker image history
command:
docker image history IMAGE
Replace IMAGE
with the image ID, repository name, or repository name with tag.
For example, to display the history of the ubuntu:20.04
image, use:
docker image history ubuntu:20.04
Pull Docker images:
To pull an image from a registry, use the docker image pull
command:
docker image pull REPOSITORY[:TAG]
Replace REPOSITORY
with the image repository name and TAG
with the desired image tag. If no tag is provided, Docker will pull the "latest" tag by default.
For example, to pull the alpine:3.14
image, use:
docker image pull alpine:3.14
Push Docker images:
To push an image to a registry, use the docker image push
command:
docker image push REPOSITORY[:TAG]
Replace REPOSITORY
with the image repository name and TAG
with the desired image tag. You need to be logged in to the registry using docker login
before you can push images.
For example, to push the myrepo/myimage:1.0
image to Docker Hub, use:
docker image push myrepo/myimage:1.0
In this tutorial, we covered the basics of using the docker image
command and its subcommands for managing Docker images. These commands offer a consistent interface for working with images, from listing and inspecting to pulling and pushing images to registries.
How to Use Docker Images:
docker images
command lists the Docker images available on your local machine, providing information about repositories, tags, and sizes.docker images
Docker Image Pull and Push Commands:
docker pull
to download images from a registry, and docker push
to upload images to a registry.docker pull ubuntu:latest docker push myrepository/myimage:tag
Tagging and Versioning Docker Images:
docker tag myimage:latest myimage:v1.0
Optimizing Docker Image Size:
FROM alpine:latest RUN apk --no-cache add my-dependency