Deleting a Container Image
You can delete unnecessary container images to free up drive space.
- Delete a container
- Log in to the server as the root user.
- Run the following command to check the value of CONTAINER ID:
1 2 3 4
# View running containers. docker ps # View all containers. docker ps -a
Information similar to the following is displayed (the container ID is 5f45daf9eb8f):
1 2
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 5f45daf9eb8f ascend-toolkit:8.0.0 "/bin/bash" 39 seconds ago Up 28 minutes boring_wright
- Before deleting a running container, stop it first. If the container to be deleted is stopped, skip this step.
1docker stop <CONTAINER ID>
Replace <CONTAINER ID> with the container ID queried in the preceding step.
- Run the following command to delete the container:
1docker rm <CONTAINER ID>
- Delete an image
Before deleting an image, delete the containers that depend on the image. To delete an image, perform the following steps:
- Delete the container that depends on the image by referring to 1 to 4. If no container depends on the image, skip this step.
- Run the docker images command to view the IMAGE ID.
Information similar to the following is displayed (the image ID is feb5d9fea6a5):
1 2
REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/hello-world latest feb5d9fea6a5 14 months ago 13.3 kB
- Run the following command to delete the image.
1docker rmi <IMAGE ID>
Parent topic: Common Operations for Container Deployment