Commands & Use Cases
About
This page provides commonly used Docker commands organized by real-world scenarios. It serves as a quick reference for tasks such as managing images, containers, volumes, and performing system cleanups. Each command is explained with its purpose to help streamline day-to-day Docker usage.
Docker Image
List all the images
To list all the docker images available:
docker imagesRemove Dangling Images
To remove Docker images with the tag <none>, we can use the following command in our terminal or command prompt:
docker rmi $(docker images -f "dangling=true" -q)This command first lists all dangling images (images without a tag) using docker images -f "dangling=true" -q, then removes them using docker rmi
Back up Specific Docker images
If we want to back up our Docker images to our local system, we can use the docker save command to export the images to a tar archive file.
List all the images we want to back up:
docker imagesIdentify the image IDs or names we want to back up.
Use the
docker savecommand to export the images to a tar archive. We can specify multiple images by separating them with spaces:
Replace IMAGE_ID_1, IMAGE_ID_2, etc., with the IDs or names of the images we want to back up.
For example, if we want to back up two images with IDs 123abc and 456def, we would run:
This command will create a file named backup.tar containing the specified Docker images.
After creating the backup, we can transfer the backup.tar file to our desired location for safekeeping.
Note: The docker save command exports Docker images without preserving their tags.
If we want to retain the tags along with the images, we can use a combination of docker save and docker inspect commands.
List all the images we want to back up:
Identify the image IDs or names we want to back up.
Use the
docker inspectcommand to get the tags associated with the images:
Replace IMAGE_ID_1, IMAGE_ID_2, etc., with the IDs or names of the images we want to back up.
Combine the
docker saveanddocker inspectcommands to export the images with their tags:
This command will create tar files with names like backup_REPOSITORY_TAG.tar for each image, preserving both repository and tag information.
Replace IMAGE_ID_1, IMAGE_ID_2, etc., with the IDs or names of the images we want to back up.
Last updated