Docker Image Cheatsheet
A Docker image is a read-only, static template that contains the instructions for creating a Docker container. Here are the most common commands for managing images.
Basic Image Operations
These commands are for managing images on your local machine.
| Command | Description |
|---|---|
docker build -t [NAME]:[TAG] . | Builds a new image from a Dockerfile in the current directory, tagging it with a name and version. |
docker images | Lists all images stored on your local machine. You can also use docker image ls. |
docker tag [SOURCE_IMAGE]:[TAG] [TARGET_IMAGE]:[TAG] | Creates a new tag (alias) for an existing image. This is useful for versioning or preparing an image to be pushed to a registry. |
docker rmi [IMAGE_ID or IMAGE_NAME] | Removes an image from your local machine. Use the -f flag to force removal of an image used by a stopped container. |
Sharing Images
These commands are for sharing images with others, either through a registry or by manual transfer.
| Command | Description |
|---|---|
docker push [IMAGE]:[TAG] | Uploads a tagged image to a Docker registry (e.g., Docker Hub). You must first log in using docker login. |
docker pull [IMAGE]:[TAG] | Downloads an image from a Docker registry. |
docker save -o [FILE].tar [IMAGE]:[TAG] | Saves one or more images into a .tar archive. Useful for sharing images without a registry. |
docker load -i [FILE].tar | Loads a .tar archive from a file into the local Docker image cache. |