如何编辑现有的 docker 图像元数据? [英] How can I edit an existing docker image metadata?

查看:27
本文介绍了如何编辑现有的 docker 图像元数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于以下原因,我想编辑 docker 图像元数据:

I would like to edit a docker images metadata for the following reasons:

  • 我不喜欢图像父母 EXPOSE、VOLUME 等声明(参见 #3465,Docker-Team 不想提供解决方案),所以我想取消音量"或取消公开"图像.

  • I don't like an image parents EXPOSE, VOLUME etc declaration (see #3465, Docker-Team did not want to provide a solution), so I'd like to "un-volume" or "un-expose" the image.

我不喜欢图像 ContainerConfig(请参阅 docker inspect [image])因为它是使用 docker commit 从正在运行的容器生成的[容器]

I dont't like an image ContainerConfig (see docker inspect [image]) cause it was generated from a running container using docker commit [container]

修复 docker builddocker run 期间的错误,例如:
无法在现有文件上挂载卷,文件存在 [路径]

Fix error durring docker build or docker run like:
cannot mount volume over existing file, file exists [path]

有什么办法可以做到吗?

Is there any way I can do that?

推荐答案

它有点hacky,但有效:

Its a bit hacky, but works:

  1. 将图像保存到 tar.gz 文件中:
    $ docker save [图像] >[目标文件.tar.gz]

解压 tar 文件以访问原始图像数据:
tar -xvzf [targetfile.tar.gz]

Extract the tar file to get access to the raw image data:
tar -xvzf [targetfile.tar.gz]

manifest.json 文件中查找图像元数据文件:应该有一个类似 .Config 的键,其中包含一个 [HEX]号码.提取文件夹的根目录中应该有一个准确的 [HEX].json.
这是包含图像元数据的文件.随意编辑.

Lookup the image metadata file in the manifest.json file: There should be a key like .Config which contains a [HEX] number. There should be an exact [HEX].json in the root of the extracted folder.
This is the file containing the image metadata. Edit as you like.

将提取的文件打包回new.tar.gz-archive

Pack the extracted files back into an new.tar.gz-archive

使用 cat [new.tar.gz] |docker load 重新导入修改后的镜像

Use cat [new.tar.gz] | docker load to re-import the modified image

使用 docker inspect [image] 验证您的元数据更改是否已应用

Use docker inspect [image] to verify your metadata changes have been applied

这篇关于如何编辑现有的 docker 图像元数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆