泊坞窗:从图像中提取图层 [英] docker: extracting a layer from a image
问题描述
让我们以鲸鱼图像为例。 docker history
显示以下内容:
Let's take the whalesay images as an example. docker history
shows the following:
IMAGE CREATED CREATED BY SIZE COMMENT
6b362a9f73eb 17 months ago /bin/sh -c #(nop) ENV PATH=/usr/local/bin:/us 0 B
<missing> 17 months ago /bin/sh -c sh install.sh 30.37 kB
<missing> 17 months ago /bin/sh -c git reset --hard origin/master 43.27 kB
<missing> 17 months ago /bin/sh -c #(nop) WORKDIR /cowsay 0 B
<missing> 17 months ago /bin/sh -c git clone https://github.com/moxie 89.9 kB
<missing> 17 months ago /bin/sh -c apt-get -y update && apt-get insta 58.58 MB
<missing> 18 months ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0 B
<missing> 18 months ago /bin/sh -c sed -i 's/^#\s*\(deb.*universe\)$/ 1.895 kB
<missing> 18 months ago /bin/sh -c echo '#!/bin/sh' > /usr/sbin/polic 194.5 kB
<missing> 18 months ago /bin/sh -c #(nop) ADD file:f4d7b4b3402b5c53f2 188.1 MB
I' d想提取显示 ADD file:bla
的图层。有没有执行此操作的工具/方法?
I'd like to extract the layer that says ADD file:bla
. Is there a tool/way for doing this?
推荐答案
在这种情况下,它看起来像 ADD
命令将基本映像添加到文件系统。如果您运行 docker history --no-trunc docker / whalesay
,则完整命令为:
In this specific case, it looks like the ADD
command added the base image to the file system. If you run docker history --no-trunc docker/whalesay
, the full command is:
/bin/sh -c #(nop) ADD file:f4d7b4b3402b5c53f266bb7fdd7e728493d9a17f9ef20c8cb1b4759b6e66b70f in /
docker history
报告特定层为188MB。让我们更详细地看一下这些层:
docker history
reports that particular layer is 188MB. Let's look at these layers in more detail:
$ docker save docker/whalesay -o whalesay.tar
$ tar tvf whalesay.tar
...
-rw-r--r-- 0/0 197181952 2015-05-25 22:04 cc88f763e297503d2407d6b462b2b390a6fd006b30f51c8efa03dd88fa801b89/layer.tar
...
看起来像一个不错的候选人!现在,您可以提取该层并从中提取文件。
Looks like a pretty good candidate! You can now extract that layer and pull files out of it.
$ tar xf whalesay.tar cc88f763e297503d2407d6b462b2b390a6fd006b30f51c8efa03dd88fa801b89/layer.tar
$ tar xf cc88f763e297503d2407d6b462b2b390a6fd006b30f51c8efa03dd88fa801b89/layer.tar etc/passwd
如果您要拉一个特定文件不在图层中,但是您不知道哪个图层,您可以执行此操作。首先,提取所有图层:
If you're looking to pull a particular file out of a layer, but you don't know which layer, you could do this. First, extract all the layers:
$ tar xf whalesay.tar
现在,您已经将所有图层作为单独的.tar文件。让我们找到一个文件:
Now you've got all the layers as individual .tar files. Let's find a file:
$ for layer in */layer.tar; do tar -tf $layer | grep docker.cow && echo $layer; done
usr/local/share/cows/docker.cow
0523c5a0c4588dde33d61d171c41c2dc5c829db359f4d56ab896ab1c185ed936/layer.tar
cowsay/cows/docker.cow
40e8ae7bb4e5b9eaac56f5be7aa614ed50f163020c87ba59e905e01ef0af0a4f/layer.tar
cowsay/cows/docker.cow
f9bc8676543761ff3033813257937aeb77e9bc84296eaf025e27fe01643927cf/layer.tar
最后,从文件中提取文件所需的图层:
Finally, extract the file from the layer you want:
$ tar xf 0523c5a0c4588dde33d61d171c41c2dc5c829db359f4d56ab896ab1c185ed936/layer.tar \
usr/local/share/cows/docker.cow
这将提取具有相对于当前目录的完整路径的文件。
This will extract that file with the full path relative to the current directory.
$ cat usr/local/share/cows/docker.cow
##
## Docker Cow
##
$the_cow = <<EOC;
$thoughts
$thoughts
$thoughts
## .
## ## ## ==
## ## ## ## ===
/""""""""""""""""\___/ ===
~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ / ===- ~~~
\\______ o __/
\\ \\ __/
\\____\\______/
EOC
这篇关于泊坞窗:从图像中提取图层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!