The short answer
To remove and un-tag a single Docker image from your local machine, you can use the docker rmi command followed the the identifier of the image you want to remove:
$ docker rmi <image_id>
Run in Warp
Note that you will first need to stop and remove all the containers currently using this image in order to be able to remove it.
You can learn more about this by reading our article on how to remove all stopped Docker containers.
Easily retrieve this command using Warp’s AI Command Search
If you’re using Warp as your terminal, you can easily retrieve this command using the Warp AI Command Search feature:
Entering docker remove image in the AI Command Search will prompt an docker command that can then quickly be inserted into your shell by doing CMD+ENTER.
Removing an image from the local machine
A Docker image can be removed using either its short or long identifier, its tag, or its digest. To get this information, you can run the docker images command, which will list all the locally downloaded images:
$ docker images
Run in Warp
You can then use one of the methods described below to remove one or more images. Alternatively, you can also read our article on how to remove all Docker images at once.
Removing an image using its tag
A tag is a string of characters used to identify a specific version of an image (e.g. latest, v1.0).
To remove an image based on its tag, you can use the following syntax:
$ docker rmi <image:tag>
Run in Warp
For example, the following command will remove the mysql image version 8:
$ docker rmi mysql:8
Run in Warp
Note that if an image has one or more tags referencing it, you must remove all of them before the image is removed.
Removing an image using its digest
A Docker image digest is an immutable identifier created during the build time of the image.
Since a digest cannot be altered or tampered with, unlike a name or tag, it is sometimes preferable to use it in order to prevent the accidental removal of unwanted images, especially when working with scripts or automation.
To remove a Docker image using its digest, you can use the following syntax:
$ docker rmi <image>@<digest>
Run in Warp
For example, the following command will remove the mysql image based on its digest value:
$ docker rmi mysql@sha256:15f069202c46cf861ce429423ae3f8dfa6423306fbf399eaef36094ce30dd75c
Run in Warp
Note that to list all images including their digest, you can use the docker images --digests command.
Forcing the image removal
To force the removal of a Docker image, regardless of whether it is currently used by containers or has multiple tags associated with it, you can use the docker rmi command with the -f flag (short for force) as follows:
$ docker rmi -f <image>
Run in Warp
Note that this command should be used with caution as it may provoke the unexpected disruption of running applications.
Removing an image from a Docker registry
To remove an image from an online Docker registry, you must first authentication to the registry using the docker login command:
$ docker login <registry_url>
Run in Warp
List all the images present in the registry using the docker search command:
$ docker search <registry_url>
Run in Warp
And finally, run the docker rmi command using the following syntax:
$ docker rmi <registry_url>/<image>:<tag>
Run in Warp
For example:
$ docker rmi docker.io/library/nginx:latest
Run in Warp
Removing an image from Artifactory
To remove a Docker image from Artifactory, you can use the following curl command:
$ curl -u <username>:<password> -X DELETE "<artifactory_url>/artifactory/<repository>/<image>:<tag>"
Run in Warp
Where:
- username is your Artifactory username.
- password is your Artifactory password.
- artifactory_url is the URL of your Artifactory instance.
- repository is the name of the repository where the Docker image is stored.
- image is the name of the Docker image you want to remove.
- tag is the tag of the Docker image you want to remove.
Written by
Razvan Ludosanu
Founder, learnbackend.dev
Filed Under
Related Articles
Override the Container Entrypoint With docker run
Learn how to override and customize the entrypoint of a Docker container using the docker run command.
The Dockerfile ARG Instruction
Learn how to define and set build-time variables for Docker images using the ARG instruction and the --build-arg flag.
Start a Docker Container
Learn how to start a new Docker container from an image in both the foreground and the background using the docker-run command.
Stop All Docker Containers
How to gracefully shutdown running containers and forcefully kill unresponsive containers with signals in Docker using the docker-stop and docker-kill commands.
Use An .env File In Docker
Learn how to write and use .env files in Docker to populate the environment of containers on startup.
Run SSH In Docker
Learn how to launch and connect to a containerized SSH server in Docker using password-based authentication and SSH keys.
Launch MySQL Using Docker Compose
Learn how to launch a MySQL container in Docker Compose.
Execute in a Docker Container
Learn how to execute one or multiple commands in a Docker container using the docker exec command.
Expose Docker Container Ports
Learn how to publish and expose Docker container ports using the docker run command and Dockerfiles.
Restart Containers In Docker Compose
Learn how to restart and rebuild one or more containers in Docker Compose.
Output Logs in Docker Compose
Learn how to output, monitor, customize and filter the logs of the containers related to one or more services in Docker Compose
Rename A Docker Image
Learn how to rename Docker images locally and remotely using the docker tag command.