部署Docker----解決刪除<none>鏡像問題
在Docker使用中,經常會碰到刪除鏡像不成功,反而讓鏡像變成了<none > <none>即,沒名字,沒Tag的鏡像。
root@iZ28ikebrg6Z:/var/run# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
<none> <none> def2e0b08cbc About an hour ago 1.37 GB
sameersbn/redmine latest f0bec095f291 2 hours ago 614.6 MB
sameersbn/gitlab latest bf5c375d9057 3 days ago 635.1 MB
<none> <none> 9cbaf023786c 3 days ago 192.8 MB
sameersbn/postgresql latest 24a6064fa4cd 10 days ago 142.1 MB
<none> <none> 48648094d099 5 weeks ago 997.9 MB
<none> <none> 195fa62e92a8 6 weeks ago 496.4 MB
training/webapp latest 31fa814ba25a 4 months ago 278.8 MB
sameersbn/redmine 2.4.2 b95b8046d47c 8 months ago 1.327 GB
好多,刪又刪不了。這主要是一些container使用了該image導致的,不僅僅是說現在運行的容器,之前運行的也會。
docker ps -a
可以查歷史記錄,然後將container commit成鏡像。
我們需要刪除這些依賴Image的container,當使用到該鏡像的所有container都刪除了,就可以直接用IMAGE_ID來刪除該鏡像。
root@iZ28ikebrg6Z:/var/run# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5d6373cb79e6 224b40d4b89f "/bin/sh -c ‘apt-get 25 hours ago Exited (0) 25 hours ago distracted_blackwell
aa47ba8e71c8 training/webapp:latest "python app.py" 28 hours ago Exited (-1) 27 hours ago suspicious_ardinghelli
09792841c0b4 training/webapp:latest "python app.py" 29 hours ago Exited (-1) 27 hours ago compassionate_torvalds
d8eca9742031 9cbaf023786c "/bin/sh -c ‘while t 31 hours ago Exited (-1) 30 hours ago mad_jones
95d20e5442f9 9cbaf023786c "/bin/bash" 31 hours ago Exited (0) 31 hours ago stupefied_torvalds
9d40292642e6 9cbaf023786c "/bin/echo ‘hello wo 31 hours ago Exited (0) 31 hours ago stoic_mclean
1078d5bd868e 9cbaf023786c "/bin/echo ‘hello wo 31 hours ago Exited (0) 31 hours ago high_leakey
e88cad8893f5 9cbaf023786c "/bin/echo hello" 31 hours ago Exited (0) 31 hours ago compassionate_mclean
0949d7b6148d 9cbaf023786c "/bin/echo ‘hello wo 31 hours ago Exited (0) 31 hours ago romantic_carson
e5ab0f35322f 9cbaf023786c "/bin/bash" 31 hours ago Exited (0) 31 hours ago romantic_elion
9fbad8b573d3 9cbaf023786c "/bin/bash" 32 hours ago Exited (0) 31 hours ago thirsty_davinci
9ce1789ee43d 9cbaf023786c "/bin/echo hello" 32 hours ago Exited (0) 32 hours ago insane_colden
一個個的刪除
root@iZ28ikebrg6Z:/var/run# docker rm 5d63
5d63
root@iZ28ikebrg6Z:/var/run# docker rm aa47
aa47
root@iZ28ikebrg6Z:/var/run# docker rm 0979
0979
root@iZ28ikebrg6Z:/var/run# docker rm d8ec
d8ec
root@iZ28ikebrg6Z:/var/run# docker rm 95d
95d
root@iZ28ikebrg6Z:/var/run# docker rm 9d4
9d4
root@iZ28ikebrg6Z:/var/run# docker rm 1078
1078
root@iZ28ikebrg6Z:/var/run# docker rm e88c
e88c
root@iZ28ikebrg6Z:/var/run# docker rm 0949
0949
root@iZ28ikebrg6Z:/var/run# docker rm e5ab
e5ab
root@iZ28ikebrg6Z:/var/run# docker rm 9fba
9fba
root@iZ28ikebrg6Z:/var/run# docker rm 9ce1
9ce1
root@iZ28ikebrg6Z:/var/run# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
root@iZ28ikebrg6Z:/var/run# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
sameersbn/redmine latest f0bec095f291 3 hours ago 614.6 MB
sameersbn/gitlab latest bf5c375d9057 3 days ago 635.1 MB
sameersbn/postgresql latest 24a6064fa4cd 10 days ago 142.1 MB
<none> <none> 48648094d099 5 weeks ago 997.9 MB
<none> <none> 195fa62e92a8 6 weeks ago 496.4 MB
training/webapp latest 31fa814ba25a 4 months ago 278.8 MB
sameersbn/redmine 2.4.2 b95b8046d47c 8 months ago 1.327 GB
root@iZ28ikebrg6Z:/var/run# docker rmi 4864
Deleted: 48648094d099bf7c38c5687f4cde3f2b7d27e8a1dc45c30d8fdf8e5f42c2473e
Deleted: 4b1b0cd0c62c3e86701bf4bc4736ca403e3ddd264101d69110bd1924bf05ec2d
Deleted: cd2308a31b296d77f1ef1562432d3908582528ed13d838a3ab6702e7d19ce604
Deleted: 212c2526444a6cefedf9d985f2727bef4b50b84062400a8f1d98b19f779baf3d
Deleted: ac89032e1c4548eaf6f6bf817850431b9180a5b7f06b29e6d7f73b4b8878fe10
Deleted: dcd2c451d11f4896c31b0178c41bf764a87625004ff0048863e627474147c413
Deleted: 7eac533353c28beeab8fd4abb5a6663abc99f0cf24d3650963352f3a41ce8e29
Deleted: 11ed21fa7166f4dee1cfe406885d889f07222a458e706c9d30c28aa9e4cfc398
Deleted: cf6daa523a25b1b947138ad883d18f8501d210ae110487066a9b4ccd8fbd9c70
Deleted: 830bf73bda66fe5ac8bf9262b5be7f4cfacec7a2dd28b7d8cb61c505e68fb787
Deleted: 41176d2b465f4072fa46897aef5f4e35a1941d73a20687bb704c2bfd789a5ae3
Deleted: fa078497ab6f0be3ce013f336ff052af7eaa96cbe2e14e3e6f6352c00544ede0
Deleted: 4477fcbe8e773d2699bf50a6a24b265fbede90ab95793e9cd36f1627348424ed
Deleted: 314c98eff22790bf333b9f98ff39576d9cfbeb3f380fe839ca74ef641b30d1f6
Deleted: 01fb8a54ae0821edb5d6d30280b56c47934efa05b158b67ad3a4a4bb9a82928b
Deleted: 533b41917c87f1479dd6cc852cf8ad11ccd9ef93d5b42978b66bbb1bb30dd476
Deleted: b9c0b9efe68d7fe7caa1c9dcfd61a0aa4a3fb4e2629b7d10c9140a495a438855
Deleted: a91d7692121d15b5399bfb0b4096aa7d696d9e0e0b44269479e5666ea3b39dd9
Deleted: 37d36b47338de2dca6f957a520016d9e7ca4db1e57d6eb38824c9ba267b29db7
Deleted: c4ff7513909dedf4ddf3a450aea68cd817c42e698ebccf54755973576525c416
Deleted: cc58e55aa5a53b572f3b9009eb07e50989553b95a1545a27dcec830939892dba
Deleted: 0ea0d582fd9027540c1f50c7f0149b237ed483d2b95ac8d107f9db5a912b4240
Deleted: d92c3c92fa73ba974eb409217bb86d8317b0727f42b73ef5a05153b729aaf96b
Deleted: 9942dd43ff211ba917d03637006a83934e847c003bef900e4808be8021dca7bd
Deleted: 1c9383292a8ff4c4196ff4ffa36e5ff24cb217606a8d1f471f4ad27c4690e290
root@iZ28ikebrg6Z:/var/run# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
sameersbn/redmine latest f0bec095f291 3 hours ago 614.6 MB
sameersbn/gitlab latest bf5c375d9057 3 days ago 635.1 MB
sameersbn/postgresql latest 24a6064fa4cd 10 days ago 142.1 MB
<none> <none> 195fa62e92a8 6 weeks ago 496.4 MB
training/webapp latest 31fa814ba25a 4 months ago 278.8 MB
sameersbn/redmine 2.4.2 b95b8046d47c 8 months ago 1.327 GB
root@iZ28ikebrg6Z:/var/run# docker rmi 195f
Error response from daemon: No such image: 762df2d4d7bb52a46148cf3e5ab423b30aafd58ca8f758ea78ea2cbd1b1753b6
2014/10/17 17:26:04 Error: failed to remove one or more images
root@iZ28ikebrg6Z:/var/run# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
sameersbn/redmine latest f0bec095f291 3 hours ago 614.6 MB
sameersbn/gitlab latest bf5c375d9057 3 days ago 635.1 MB
sameersbn/postgresql latest 24a6064fa4cd 10 days ago 142.1 MB
training/webapp latest 31fa814ba25a 4 months ago 278.8 MB
sameersbn/redmine 2.4.2 b95b8046d47c 8 months ago 1.327 GB
root@iZ28ikebrg6Z:/var/run#
好,刪除幹凈了。還我們一個幹凈的工作區間。
docker的刪除有兩種,一個是rm 刪除容器,一個是rmi刪除鏡像。
rm Remove one or more containers
rmi Remove one or more images
這裏有兩個不同的單詞,images和container。其中images很好理解,跟平常使用的虛擬機的鏡像一個意思,相當於一個模版,而container則是images運行時的的狀態。docker對於運行過的image都保留一個狀態(container),可以使用命令docker ps來查看正在運行的container,對於已經退出的container,則可以使用docker ps -a來查看。 如果你退出了一個container而忘記保存其中的數據,你可以使用docker ps -a來找到對應的運行過的container使用docker commit命令將其保存為image然後運行。
回到之前的問題,由於image被某個container引用(拿來運行),如果不將這個引用的container銷毀(刪除),那image肯定是不能被刪除。
所以想要刪除運行過的images必須首先刪除它的container。繼續來看剛才的例子,
[yaxin@ubox ~] "hljs-variable">$docker ps "hljs-operator">-a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ade696 ed9c93747fe1 /bin/sh -c /usr/sbin hours ago Up hours 0.0.0.0:->/tcp test_sshd
可以看出ed9c93747fe1的image被117843ade696的container使用著,所以必須首先刪除該container
[yaxin@ubox ~] "hljs-variable">$docker rm ade696
Error: container_delete: Impossible to remove a running container, please stop it first
// :: Error: failed to remove one or more containers
出現錯誤,這是因為該container正在運行中(運行docker ps查看),先將其關閉
[yaxin@ubox ~] "hljs-variable">$docker stop ade696
ade696
[yaxin@ubox ~] "hljs-variable">$docker rm ade696
ade696
[yaxin@ubox ~] "hljs-variable">$docker rmi ed9c93747fe1
Deleted: ed9c93747fe16627be822ad3f7feeb8b4468200e5357877d3046aa83cc44c6af
Deleted: c8a0c19429daf73074040a14e527ad5734e70363c644f18c6815388b63eedc9b
Deleted: dba4c468f0e53e5f1e5d76b8581d6740aab9f59141f783f8e263ccd7cf2a8e
Deleted: c25dc743e40af6858c34375d450851bd606a70ace5d04e231a7fcc6d2ea23cc1
Deleted: f5714a5ce764845119399ef75e652e23135cd5c54265ff8218b61ccbd33
Deleted: c8af1dc23af7a7aea0c25ba9b28bdee68caa8866f056e4f2aa2a5fa1bcb12693
Deleted: fdb2c5432e08ec6121f8dbb17e1fde17d5db4c1f149a9b702785dbf7b0f3be
Deleted: ca14274c80ac1df1333b89b2a41c0e0e3b91cd1b267b31bef852ceab3b2044
[yaxin@ubox ~]$docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
CentOS65 latest e55a74a32125 days ago 360.6 MB
可以看出,image已經被刪除
本文出自 “愛生活的小白” 博客,請務必保留此出處http://sf1314.blog.51cto.com/13295031/1975995
部署Docker----解決刪除<none>鏡像問題