반응형
1. 이미지 삭제 순서 : 컨테이너삭제 → 이미지 삭제
## 이미지 삭제 : docker rmi <image id>
## 지우려는 이미지로 실행되어진 컨테이너가 있을경우 이미지 삭제는 진행되지 않음
[root@docker]# docker rmi nginx:add_plo
Error response from daemon: conflict: unable to remove repository reference "nginx:add_plo" (must force) - container b92a93ef0cde is using its referenced image 1ce4194fd0ba
## 지우려는 이미지로 실행되어진 컨테이너 검색
[root@docker]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4c8eb3200b02 nginx:latest "/docker-entrypoint.…" About a minute ago Exited (0) 38 seconds ago upbeat_swirles
bc14e33a6f9b nginx:latest "/docker-entrypoint.…" 4 minutes ago Exited (130) 4 minutes ago boring_wilbur
a87da603ea53 nginx:latest "/docker-entrypoint.…" 6 minutes ago Exited (0) 4 minutes ago festive_cray
d792944cb7f2 nginx:latest "/docker-entrypoint.…" 6 minutes ago Exited (0) 6 minutes ago vigorous_hawking
7286088a5e21 nginx:latest "/docker-entrypoint.…" 10 minutes ago Exited (0) 6 minutes ago dreamy_yonath
b92a93ef0cde nginx:add_plo "/docker-entrypoint.…" 11 minutes ago Exited (0) 11 minutes ago practical_dhawan
dd8043840d5a centos:test "bash" 42 minutes ago Exited (127) 42 minutes ago angry_kirch
0b6b8812186c centos:latest "bash" 42 minutes ago Exited (0) 42 minutes ago nervous_banzai
da3e928eea4b nginx:add_plo "/docker-entrypoint.…" 2 hours ago Exited (0) 11 minutes ago great_nightingale
57d7ca8ca5d0 nginx:latest "/docker-entrypoint.…" 2 hours ago Exited (0) 2 hours ago charming_dirac
40ca2c420d22 nginx:latest "/docker-entrypoint.…" 2 hours ago Exited (0) 2 hours ago xenodochial_rubin
4ea2a6ea93e7 nginx:latest "/docker-entrypoint.…" 3 hours ago Exited (0) 3 hours ago vibrant_banach
b582f1bf7c1d nginx:latest "/docker-entrypoint.…" 3 hours ago Exited (0) 3 hours ago sleepy_blackwell
20ed27aec214 nginx:latest "/docker-entrypoint.…" 3 hours ago Exited (0) 3 hours ago clever_shaw
## 연관 컨테이너 삭제
[root@docker]# docker rm b92a93ef0cde
b92a93ef0cde
[root@docker]# docker rmi nginx:add_plo
Error response from daemon: conflict: unable to remove repository reference "nginx:add_plo" (must force) - container da3e928eea4b is using its referenced image 1ce4194fd0ba
[root@docker]# docker rm da3e928eea4b
da3e928eea4b
## 이미지 삭제
[root@docker]# docker rmi nginx:add_plo
Untagged: nginx:add_plo
Deleted: sha256:1ce4194fd0ba2400726bb4cd92d3d6012764dc5cccf3be3d7bd73a2a808dbdd4
Deleted: sha256:d704bac382ba0f9e7929ea5e8ea8787c8bb453e1b3d48c3c12cdb7307aa5a08f
## 확인
[root@docker]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4c8eb3200b02 nginx:latest "/docker-entrypoint.…" 2 minutes ago Exited (0) 2 minutes ago upbeat_swirles
bc14e33a6f9b nginx:latest "/docker-entrypoint.…" 5 minutes ago Exited (130) 5 minutes ago boring_wilbur
a87da603ea53 nginx:latest "/docker-entrypoint.…" 7 minutes ago Exited (0) 6 minutes ago festive_cray
d792944cb7f2 nginx:latest "/docker-entrypoint.…" 8 minutes ago Exited (0) 7 minutes ago vigorous_hawking
7286088a5e21 nginx:latest "/docker-entrypoint.…" 12 minutes ago Exited (0) 8 minutes ago dreamy_yonath
dd8043840d5a centos:test "bash" 44 minutes ago Exited (127) 43 minutes ago angry_kirch
0b6b8812186c centos:latest "bash" 44 minutes ago Exited (0) 44 minutes ago nervous_banzai
57d7ca8ca5d0 nginx:latest "/docker-entrypoint.…" 2 hours ago Exited (0) 2 hours ago charming_dirac
40ca2c420d22 nginx:latest "/docker-entrypoint.…" 2 hours ago Exited (0) 2 hours ago xenodochial_rubin
4ea2a6ea93e7 nginx:latest "/docker-entrypoint.…" 3 hours ago Exited (0) 3 hours ago vibrant_banach
b582f1bf7c1d nginx:latest "/docker-entrypoint.…" 3 hours ago Exited (0) 3 hours ago sleepy_blackwell
20ed27aec214 nginx:latest "/docker-entrypoint.…" 3 hours ago Exited (0) 3 hours ago clever_shaw
[root@OPENLDAP-TEST 5b06bfad8b594fb3189e77fb3c9078ff734292d4ec0ca068f2ff41ba863a92d2]# docker images -a
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 8cf1bfb43ff5 Less than a second ago 132MB
centos test 245b08b27f6f 45 minutes ago 253MB
centos latest 831691599b88 3 weeks ago 215MB
2. docker rmi -f <image ID> : 연관 컨테이너에 상관없이 강제로 삭제한다.
## centos:test 이미지로 생성된 컨테이너 존재
[root@docker]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4c8eb3200b02 8cf1bfb43ff5 "/docker-entrypoint.…" 9 minutes ago Exited (0) 9 minutes ago upbeat_swirles
bc14e33a6f9b 8cf1bfb43ff5 "/docker-entrypoint.…" 13 minutes ago Exited (130) 12 minutes ago boring_wilbur
a87da603ea53 8cf1bfb43ff5 "/docker-entrypoint.…" 14 minutes ago Exited (0) 13 minutes ago festive_cray
d792944cb7f2 8cf1bfb43ff5 "/docker-entrypoint.…" 15 minutes ago Exited (0) 15 minutes ago vigorous_hawking
7286088a5e21 8cf1bfb43ff5 "/docker-entrypoint.…" 19 minutes ago Exited (0) 15 minutes ago dreamy_yonath
dd8043840d5a centos:test "bash" 51 minutes ago Exited (127) 50 minutes ago angry_kirch
0b6b8812186c 831691599b88 "bash" 51 minutes ago Exited (0) 51 minutes ago nervous_banzai
57d7ca8ca5d0 8cf1bfb43ff5 "/docker-entrypoint.…" 2 hours ago Exited (0) 2 hours ago charming_dirac
40ca2c420d22 8cf1bfb43ff5 "/docker-entrypoint.…" 3 hours ago Exited (0) 2 hours ago xenodochial_rubin
4ea2a6ea93e7 8cf1bfb43ff5 "/docker-entrypoint.…" 3 hours ago Exited (0) 3 hours ago vibrant_banach
b582f1bf7c1d 8cf1bfb43ff5 "/docker-entrypoint.…" 3 hours ago Exited (0) 3 hours ago sleepy_blackwell
20ed27aec214 8cf1bfb43ff5 "/docker-entrypoint.…" 3 hours ago Exited (0) 3 hours ago clever_shaw
## centos:test 이미지 강제 삭제
[root@docker]# docker rmi -f centos:test
Untagged: centos:test
Deleted: sha256:245b08b27f6f75d33c60b0321fc86bd11ca53535a339697710c87466565a4426
## 이미지 ID가 남고 컨테이너는 지워지지 않는다.
[root@docker]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4c8eb3200b02 8cf1bfb43ff5 "/docker-entrypoint.…" 9 minutes ago Exited (0) 9 minutes ago upbeat_swirles
bc14e33a6f9b 8cf1bfb43ff5 "/docker-entrypoint.…" 13 minutes ago Exited (130) 13 minutes ago boring_wilbur
a87da603ea53 8cf1bfb43ff5 "/docker-entrypoint.…" 15 minutes ago Exited (0) 13 minutes ago festive_cray
d792944cb7f2 8cf1bfb43ff5 "/docker-entrypoint.…" 15 minutes ago Exited (0) 15 minutes ago vigorous_hawking
7286088a5e21 8cf1bfb43ff5 "/docker-entrypoint.…" 19 minutes ago Exited (0) 15 minutes ago dreamy_yonath
dd8043840d5a 245b08b27f6f "bash" 51 minutes ago Exited (127) 50 minutes ago angry_kirch
0b6b8812186c 831691599b88 "bash" 51 minutes ago Exited (0) 51 minutes ago nervous_banzai
57d7ca8ca5d0 8cf1bfb43ff5 "/docker-entrypoint.…" 2 hours ago Exited (0) 2 hours ago charming_dirac
40ca2c420d22 8cf1bfb43ff5 "/docker-entrypoint.…" 3 hours ago Exited (0) 2 hours ago xenodochial_rubin
4ea2a6ea93e7 8cf1bfb43ff5 "/docker-entrypoint.…" 3 hours ago Exited (0) 3 hours ago vibrant_banach
b582f1bf7c1d 8cf1bfb43ff5 "/docker-entrypoint.…" 3 hours ago Exited (0) 3 hours ago sleepy_blackwell
20ed27aec214 8cf1bfb43ff5 "/docker-entrypoint.…" 3 hours ago Exited (0) 3 hours ago clever_shaw
3. 모든 컨테이너 삭제
## 현재 존재하는 모든 컨테이너 목록
[root@docker]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4c8eb3200b02 8cf1bfb43ff5 "/docker-entrypoint.…" 9 minutes ago Exited (0) 9 minutes ago upbeat_swirles
bc14e33a6f9b 8cf1bfb43ff5 "/docker-entrypoint.…" 13 minutes ago Exited (130) 13 minutes ago boring_wilbur
a87da603ea53 8cf1bfb43ff5 "/docker-entrypoint.…" 15 minutes ago Exited (0) 13 minutes ago festive_cray
d792944cb7f2 8cf1bfb43ff5 "/docker-entrypoint.…" 15 minutes ago Exited (0) 15 minutes ago vigorous_hawking
7286088a5e21 8cf1bfb43ff5 "/docker-entrypoint.…" 19 minutes ago Exited (0) 15 minutes ago dreamy_yonath
dd8043840d5a 245b08b27f6f "bash" 51 minutes ago Exited (127) 50 minutes ago angry_kirch
0b6b8812186c 831691599b88 "bash" 51 minutes ago Exited (0) 51 minutes ago nervous_banzai
57d7ca8ca5d0 8cf1bfb43ff5 "/docker-entrypoint.…" 2 hours ago Exited (0) 2 hours ago charming_dirac
40ca2c420d22 8cf1bfb43ff5 "/docker-entrypoint.…" 3 hours ago Exited (0) 2 hours ago xenodochial_rubin
4ea2a6ea93e7 8cf1bfb43ff5 "/docker-entrypoint.…" 3 hours ago Exited (0) 3 hours ago vibrant_banach
b582f1bf7c1d 8cf1bfb43ff5 "/docker-entrypoint.…" 3 hours ago Exited (0) 3 hours ago sleepy_blackwell
20ed27aec214 8cf1bfb43ff5 "/docker-entrypoint.…" 3 hours ago Exited (0) 3 hours ago clever_shaw
## 다음과 같이 하나씩 지워도 됨
[root@docker]# docker rm 4c8eb3200b02
4c8eb3200b02
[root@docker]# docker rm bc14e33a6f9b
bc14e33a6f9b
## 다음과 같이 컨테이너 ID만 출력 명령어를 이용
[root@docker]# docker ps -a -q
a87da603ea53
d792944cb7f2
7286088a5e21
dd8043840d5a
0b6b8812186c
57d7ca8ca5d0
40ca2c420d22
4ea2a6ea93e7
b582f1bf7c1d
20ed27aec214
## 모든 컨테이너 삭제
[root@docker]# docker rm `docker ps -a -q`
a87da603ea53
d792944cb7f2
7286088a5e21
dd8043840d5a
0b6b8812186c
57d7ca8ca5d0
40ca2c420d22
4ea2a6ea93e7
b582f1bf7c1d
20ed27aec214
## 확인
[root@docker]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
반응형
'Micro Service Architecture > Docker' 카테고리의 다른 글
7. [docker] Orchestration (Docker Swarm) 구축 : Manager, Worker Node 구성 (0) | 2021.03.16 |
---|---|
5. [docker] container run (0) | 2021.03.16 |
3. [docker] dockerfile build (0) | 2021.03.16 |
2. [docker] images commit (0) | 2021.03.16 |
1. [docker] images (0) | 2021.03.16 |