A Docker image is a self-contained package that includes everything needed to run a software application — code, runtime, libraries, environment variables, and configuration files. Images are built in layers, with each layer representing a specific change, which makes them efficient to store and distribute. This guide covers managing Docker images with the Docker CLI: pulling, tagging, pushing, removing, and inspecting images, plus checking an image's layer history. By the end, you'll be comfortable moving images between your local machine and a remote registry and cleaning up the ones you no longer need.
1. Pull Images with docker image pull
Docker images are stored in registries, such as Docker Hub, which host prebuilt images for popular operating systems, frameworks, and applications. docker image pull downloads an image from a remote registry to your local machine, making it available for creating and running containers.
1. Pull the latest nginx image:
$ docker image pull nginx
This pulls the nginx image from the registry using the latest tag.
2. Pull all tags of an image:
$ docker image pull -a nginx
This pulls every available tag of nginx from the registry.
2. Tag and Push Images with docker image push
docker image push uploads a local image to a remote registry. Before pushing, tag the image using the standard format [registry-hostname[:port]]/repository[:tag].
1. Tag the local image:
$ docker image tag app:latest myuser/app:v1
This doesn't change the original app:latest image — it creates a new tag, myuser/app:v1, pointing to the same image ID. Replace myuser with your registry username.
2. Push it to a remote registry:
$ docker image push myuser/app:v1
You must run docker login and authenticate before pushing to your registry.
3. Remove Images with docker image rm
docker image rm deletes one or more images from your local system, freeing up disk space or removing outdated versions.
1. List images to find the name or ID of the one you want to remove:
$ docker image ls
2. Remove the nginx image:
$ docker image rm nginx
This removes the nginx image from your system. By default, it removes the latest tag, but you can specify a different tag if needed.
3. Remove multiple images at once:
$ docker image rm mysql alpine
This removes the mysql and alpine images (their latest tags) from your system.
You can also use docker image prune to remove all unused dangling images — untagged images not referenced by any container.
4. Inspect Images with docker image inspect
docker image inspect shows how an image was constructed, including its layers. It also works on containers, secrets, and other Docker objects.
1. Inspect the nginx image:
$ docker image inspect nginx
2. Inspect an image by its ID:
$ docker image inspect 9592f5595f2b
Both commands return the image details as JSON.
5. Check Image History with docker image history
docker image history lists the commands that created an image's layers, giving you insight into what the image is built from.
1. Check the history of the alpine image:
$ docker image history alpine
This shows the layers of the alpine image.
2. See the complete, untruncated output:
$ docker image history --no-trunc alpine
Next Steps
- Run
docker image pruneon a schedule to keep dangling images from piling up. - Set up a private registry, or a Docker Hub account, to push and version your own images.
- Fold tagging and pushing into a CI/CD pipeline so new builds publish automatically.
- Audit image history periodically to catch unnecessary layers bloating your images.
For the full guide with additional tips, visit the original article on Vultr Docs.
Top comments (0)