Docker series: 7. Remove Docker container and Images
Published in
2 min readOct 5, 2019
This article will help you delete or remove the container as well as images from the docker list.
- Let's see first for the container, how it works
[root@machine1 myImage]# docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
45fe220d4030 centos:latest “/bin/bash” 14 hours ago Up 14 hours myoscontainer
Remove container
[root@machine1 myImage]# docker container rm 45fe220d4030
Error response from daemon: You cannot remove a running container 45fe220d403029a7c7ba9baa810eea861b4b256bf50a584d45c6589dac7a2e0a. Stop the container before attempting removal or force remove
Beware: You need to stop container before removing it.
Stop the container. :)
[root@machine1 myImage]# docker container stop 45fe220d4030
45fe220d4030
List running container:
[root@machine1 myImage]# docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
List all the containers:
[root@machine1 myImage]# docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7f7d9ce61262 mycentosimage:pack1.0 “echo ‘This is Docke…” 3 minutes ago Exited (0) 3 minutes ago jovial_driscoll45fe220d4030 centos:latest “/bin/bash” 14 hours ago Exited (137) 8 seconds ago myoscontainer
Remove docker container using container id.
[root@machine1 myImage]# docker container rm 45fe220d4030
45fe220d4030[root@machine1 myImage]# docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7f7d9ce61262 mycentosimage:pack1.0 “echo ‘This is Docke…” 4 minutes ago Exited (0) 4 minutes ago jovial_driscoll
2. Let’s see first for the images, how it works
[root@machine1 myImage]# docker image rm eca72e1a5c53
Error response from daemon: conflict: unable to delete eca72e1a5c53 (must be forced) — image is being used by stopped container 7f7d9ce61262
Forcefully remove your docker image;
docker rmi -f <imageid>
[root@machine1 myImage]# docker rmi -f eca72e1a5c53
Untagged: mycentosimage:pack1.0
Deleted: sha256:eca72e1a5c5311d5cf7f83da5839e5235aa02e040d2940bb6df84f604670a7df
Deleted: sha256:1d5fb1159e18e69f6899294285575bd3f8cc4ec7e0568a73649451132bca2984
Deleted: sha256:9c6df2adc37d651878f690156393883391c03e7a3475c3027e882977c374660f
Verify:
[root@machine1 myImage]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
jacksparrow007/hadooppresetup latest 2c3a110c721e 14 hours ago 658MB
ubuntu latest 4c108a37151f 4 weeks ago 64.2MB
centos centos7 9f38484d220f 4 months ago 202MB
centos latest 9f38484d220f 4 months ago 202MB
hello-world latest fce289e99eb9 6 months ago 1.84kB
Series next read;
https://medium.com/cloudscoop/cloudscoop-docker-create-a-shellinabox-container-b85380143ef5