我想了解更多關於Docker的信息。我很初學,在這個和linux上都很新。 我的英文不完美,因此我複製了終端輸出。 我有一個516MB虛擬大小的圖像。 我在容器中啓動了bash,並使用wget將一些26MB數據下載到此容器中。下載後,我使用提交從容器的更改中創建一個映像。之後,虛擬尺寸是542.5MB。那是對的。 提交後我再次開始bash,並刪除了這個文件。 當我提交更改時,圖像虛擬大小是542.8MB。爲什麼使用rm從容器中刪除文件後虛擬大小仍然相同?
這個大小並沒有減少,反而增加了。 你能告訴我原因嗎?
本地圖片:
[[email protected] ~]$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
tester/mytestfedora latest c0ca83567bdd 4 seconds ago 516 MB
fedora latest 834629358fe2 3 months ago 241.3 MB
使用最小的一個,並下載文件:
[[email protected] ~]$ docker run -i -t tester/mytestfedora /bin/bash
bash-4.3# su dockeres
[[email protected] /]$ cd /home/dockeres/downloads/
[[email protected] downloads]$ wget https://dl.dropboxusercontent.com/u/827503/0_TEMP/Riverbed.zip
--2015-03-31 19:24:47-- https://dl.dropboxusercontent.com/u/827503/0_TEMP/Riverbed.zip
Resolving dl.dropboxusercontent.com (dl.dropboxusercontent.com)... 54.243.97.104, 54.243.80.193, 50.16.185.28, ...
Connecting to dl.dropboxusercontent.com (dl.dropboxusercontent.com)|54.243.97.104|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 26177252 (25M) [application/zip]
Saving to: 'Riverbed.zip'
Riverbed.zip 100%[==============================================================>] 24.96M 3.66MB/s in 14s
2015-03-31 19:25:03 (1.78 MB/s) - 'Riverbed.zip' saved [26177252/26177252]
[[email protected] downloads]$ exit
bash-4.3# exit
列出活動的人,並從一個容器的變化塑造新形象:
[[email protected] ~]$ docker ps -all
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
05ef6e284e32 tester/mytestfedora:latest "/bin/bash" 2 minutes ago Exited (0) 6 seconds ago sick_einstein
[[email protected] ~]$ docker commit 05ef6e284e32 tester/mytestfedora
f122b12e94a32d477f2f2f18c5a5190a9ad5d349109933da65a0cfeff448c822
[[email protected] ~]$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
tester/mytestfedora latest f122b12e94a3 5 seconds ago 542.5 MB
fedora latest 834629358fe2 3 months ago 241.3 MB
Ac再次活躍的
[[email protected] ~]$ docker run -i -t tester/mytestfedora /bin/bash
[[email protected] /]$ cd /home/dockeres/downloads/
[[email protected] downloads]$ rm -f Riverbed.zip
[[email protected] downloads]$ ls
[[email protected] downloads]$ exit
bash-4.3# exit
列表和從容器的變化塑造新形象:塞斯一遍,並刪除已下載的文件
[[email protected] ~]$ docker ps -all
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fb5ba36692f0 tester/mytestfedora:latest "/bin/bash" 51 seconds ago Exited (0) 5 seconds ago goofy_yalow
[[email protected] ~]$ docker commit fb5ba36692f0 tester/mytestfedora
f744e248576d7fa434768a1e1d25625a9654020fe77e12306f304ff5d5ad3e3b
[[email protected] ~]$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
tester/mytestfedora latest f744e248576d 3 seconds ago 542.8 MB
fedora latest 834629358fe2 3 months ago 241.3 MB
預先感謝您的任何幫助,您可以提供。
埃德
親愛的ISANYch!作爲你的樣本,我創建了這個: '從fedora RUN su -c'yum -y install unzip'\ && su -c'yum -y install wget'\ && mkdir/usr/etc \ && cd/usr/etc \ && wget -nv -O /tmp/jboss.zip http://download.jboss.org/jbossas/7.1/jboss-as-7.1.1.Final/jboss-as-7.1.1.Final。 zip \ && unzip /tmp/jboss.zip \ && yum clean all \ && rm -rf/var/cache/yum/x86_64/21/*/tmp/*/var/tmp/*' 現在,代碼我已經達到442.6 MB!這是最佳的,因爲在wget之後,解壓縮安裝而不使用jboss下載的大小爲281.3 MB。 JBoss解壓縮的大小是:〜160MB(+ 280 = 440)!謝謝ISanych,seanmcl! – edfromhadria 2015-04-01 13:18:18
順便說一下,Dockerfile(和容器中的命令)從根執行,除非你將創建並指定用戶,所以不是:su -c'yum -y install unzip'&& su -c'yum -y install wget'better使用:yum -y install unzip wget – ISanych 2015-04-01 13:23:38
明白了!通過更好的做法編輯Dockerfile。再次感謝! – edfromhadria 2015-04-01 13:31:43