After installation of Docker engine, let's explore Docker Hub & Docker Images. This article will provide information about Docker Hub, Docker Images and will also explain various Docker Images commands with example.
If you haven't installed Docker yet then checkout below articles on how to install Docker.
- What are Docker Images & Docker Hub?
- Various Docker Images command with example
- Docker Image command to get list of installed docker images
- Docker Image command to search docker images
- Docker Image command to download and install docker images
- Docker Image command to list only ID of docker images
- Docker Image command to check history of docker image
- Docker Image command to inspect docker images
- Docker Image command to delete docker images
- Docker Image command to delete docker image forcefully
- Docker Image command to delete dangling docker images
What are Docker Images & Docker Hub?
The Docker images are the set of templates and stored at Docker Hub. The Docker Hub is already integrated in the Docker setup at the time of installation and can not be removed or replaced. So whenever we have to install an image on our machine, the local machine will connect with Docker Hub to find the available images. Please refer to this official link for Docker Hub quick start guide.
Suppose if we want to install Ubuntu image then we can go the Docker Hub website and search with the Ubuntu keyword. The search will display all the matching results for Ubuntu.
To login in the Docker Hub using command line
By using docker login command you can login into the docker hub to push your custom images.
Command:
docker login
Output:
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one. Username: xxxxxxxx Password: WARNING! Your password will be stored unencrypted in /home/ec2-user/.docker/config.json. Configure a credential helper to remove this warning. See https://docs.docker.com/engine/reference/commandline/login/#credentials-store Login Succeeded
Note: The login in Docker Hub is not required for downloading and installation images.
Various Docker Images command with example
Docker Image command to get list of installed docker images
By using docker images or docker image command you can check the Docker images present on the your local .
We will execute below command to list all docker images present on local.
Command:
docker images
or
docker image ls
Output:
REPOSITORY TAG IMAGE ID CREATED SIZE
We can conclude from the output that no Docker image is present on the machine.
Docker Image command to search docker images
By using docker search command we can can search the docker images available on the Docker Hub.
Let's execute below command to search images for the Ubuntu operating system with output.
Command:
docker search ubuntu
Output:
The command will search for the images with string as ubuntu in its name and will list all the search results.
NAME DESCRIPTION STARS OFFICIAL AUTOMATED ubuntu Ubuntu is a Debian-based Linux operating sys… 10241 [OK] dorowu/ubuntu-desktop-lxde-vnc Docker image to provide HTML5 VNC interface … 369 [OK] rastasheep/ubuntu-sshd Dockerized SSH service, built on top of offi… 236 [OK] consol/ubuntu-xfce-vnc Ubuntu container with "headless" VNC session… 199 [OK] ubuntu-upstart Upstart is an event-based replacement for th… 102 [OK] ansible/ubuntu14.04-ansible Ubuntu 14.04 LTS with ansible 98 [OK] neurodebian NeuroDebian provides neuroscience research s… 61 [OK] 1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5 ubuntu-16-nginx-php-phpmyadmin-mysql-5 50 [OK]
Docker Image command to download and install docker images
The next step will be to install image from the official Docker Hub registry using docker pull command. The syntax is docker pull image_name:tag
Let's download and install ubuntu operating system image on the local where the image name is gathered from the search result.
Command:
docker pull ubuntu
In the above command, the docker will download latest image of Ubuntu as nothing is specified after image name ubuntu.
Output:
This command will by default download and install the latest Ubuntu image available on the Docker Hub.
Using default tag: latest latest: Pulling from library/ubuntu 7ddbc47eeb70: Pull complete c1bbdc448b72: Pull complete 8c3b70e39044: Pull complete 45d437916d57: Pull complete Digest: sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d Status: Downloaded newer image for ubuntu:latest
The below command will download and install trusty version of Ubuntu image from docker hub instead of latest available.
docker pull ubuntu:trusty
Let's check the available Docker images on the local system now.
docker images
Output:
REPOSITORY TAG IMAGE ID CREATED SIZE ubuntu latest 775349758637 5 weeks ago 64.2MB ubuntu trusty 2c5e00d77a67 6 months ago 188MB
Where
REPOSITORY - This is the name of the repository in the docker hub.
TAG − Used to logically tag images.
IMAGE ID − A unique identifier for the image.
CREATED − The number of days since the image was created.
SIZE − The size of the image.
Docker Image command to list only ID of docker images
docker images -q
Output:
775349758637 2c5e00d77a67
Docker Image command to check history of docker image
By using docker image history command we can check the history of modifications made in the image
Let's check history of Ubuntu image using it's image ID
Command:
docker image history 775349758637
Output:
IMAGE CREATED CREATED BY SIZE COMMENT 775349758637 5 weeks ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0B 5 weeks ago /bin/sh -c mkdir -p /run/systemd && echo 'do… 7B 5 weeks ago /bin/sh -c set -xe && echo '#!/bin/sh' > /… 745B 5 weeks ago /bin/sh -c [ -z "$(apt-get indextargets)" ] 987kB 5 weeks ago /bin/sh -c #(nop) ADD file:a48a5dc1b9dbfc632… 63.2MB
Docker Image command to inspect docker images
By using docker image inspect command we can check the detailed information of the image.
Syntax:
docker image inspect IMAGE ID
Let's inspect Ubuntu image.
Command:
docker image inspect 775349758637
In the above command, the details of the image with IMAGE ID 775349758637 will be displayed.
Docker Image command to delete docker images
By using docker rmi command you can delete docker images present on your local machine.
Syntax:
docker rmi IMAGE ID
Example:
Let's delete the Ubuntu trusty image from local machine.
Command:
docker rmi 2c5e00d77a67
In the above command we are using IMAGE ID of Ubuntu Trusty image for deletion from local machine.
Output:
Untagged: ubuntu:trusty Untagged: ubuntu@sha256:3590458403b522985068fa21888da3e351e5c72833936757c33baf9555b09e1e Deleted: sha256:2c5e00d77a67934d5e39493477f262b878f127b9c01b491f06d8f06f78819578 Deleted: sha256:664a2bb343be8b1a691e0ce9c563ee654c30a1c694dc1b25ebb5467fa3d074fd Deleted: sha256:4ac0c5a114c714b429ff471f5415974618e0b6fc743070d445cd0e2ac586cc7b Deleted: sha256:5f200444c0009c41eb39bc1cf37a5b3c2e953478f2f373c5a1873dee820e0ced Deleted: sha256:b057ab380990c219581e3b074919413ebe31079cbd0d615f63872c471b4dc633
Docker Image command to delete docker image forcefully
docker rmi -f 2c5e00d77a67
The command will untag all images matching with image ID 2c5e00d77a67 and deletes all those the images.
Docker Image command to delete dangling docker images
Dangling images are those docker images which are not associated with any tag. These unused images are just present on your disk consuming space and it's safe to delete them
Command:
Get the list of dangling images present on your local machine
docker images -f dangling=true
Delete all those dangling images
docker images purge
These are some of the Docker Image commands used frequently. For in depth Docker Image command, please check the official Docker documentation here.