问题描述
出于以下原因,我想编辑 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 build
或 docker 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:
将图像保存到 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 图像元数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!