在travis上还没有Docker缓存: https : //github.com/travis-ci/travis-ci/issues/5358
我正在尝试通过执行以下操作来编写解决方法:
`docker save -o file.tar $(docker history -q image_name | grep -v missing)` `docker load -i file.tar哪个效果很好,给了我所有的图像层。 我现在唯一的问题是节省需要很长时间,而且大部分时间我实际上都在改变一层,所以我不需要重写所有其余的。 有没有办法告诉file.tar docker save命令跳过file.tar已有的file.tar ?
Docker caching is not yet available on travis: https://github.com/travis-ci/travis-ci/issues/5358
I'm trying to write a workaround by doing:
`docker save -o file.tar $(docker history -q image_name | grep -v missing)` `docker load -i file.tarWhich works great, gives me all the image layers back. My only problem now is the saving takes a long time, and most of the time I'm actually changing one layer, so I don't need to rewrite all the rest. Is there a way of telling the docker save command to skip layers already in file.tar?
最满意答案
在tar中的manifest.json文件中,您可以获得所需的信息。
tar -xOf file.tar manifest.json
检查Config键的值。 前12个字符是图像ID。 您可以使用上面的命令,提取已有的图像ID,并在docker save命令中将其排除。
我对bash脚本不是很了解,但这可以在我的mac上运行
tar -xOf file.tar manifest.json | tr , '\n' | grep -o '"Config":".*"' | awk -F ':' '{print $2}' | awk '{print substr($0,2,12)}'
使用此输出一切
docker history -q IMAGE_HERE | grep -v missing && tar -xOf file.tar manifest.json | tr , '\n' | grep -o '"Config":".*"' | awk -F ':' '{print $2}' | awk '{print substr($0,2,12)}'
在此之后,您只需要获取唯一值。 这可以使用sort和uniq -u来完成,但由于某种原因,sort不能按预期工作。 此命令假定存在file.tar因此也要考虑到这一点。
我在docker save命令中找不到任何关于append的内容。 上述策略可以与多个文件焦点一起使用,这些焦点彼此不同。
In the manifest.json file inside the tar you have the information you need.
tar -xOf file.tar manifest.json
Check the value of the Config keys. The first 12 characters are the image id. You can use the command above, extract the image ids that you already have, and exclude them in your docker save command.
I'm not very good with bash scripting, but this works on my mac
tar -xOf file.tar manifest.json | tr , '\n' | grep -o '"Config":".*"' | awk -F ':' '{print $2}' | awk '{print substr($0,2,12)}'
Using this outputs everything
docker history -q IMAGE_HERE | grep -v missing && tar -xOf file.tar manifest.json | tr , '\n' | grep -o '"Config":".*"' | awk -F ':' '{print $2}' | awk '{print substr($0,2,12)}'
After this you only need to get the unique values. This could be done with sort and uniq -u, but for some reason, sort doesn't work as expected. This command assumes the presence of file.tar so take that into consideration too.
I couldn't find anything about append in the docker save command. The above strategy could work with multiple file tars that are all different with each other.
更多推荐
发布评论