互联网技术 / 互联网资讯 · 2024年1月2日

从Docker镜像中提取Dockerfile的方法

今天在技术群摸鱼,有朋友问个dockeR的问题,替换配置文件不生效,也没有原先的DockeRfile,所以就在想,有没有什么方式可以直接从容器或镜像生成DockeRfile

虽然dockeR HisTory命令可以看到所有历史层级的操作,但是还是需要手动去写DockeRfile

Google一番,发现dfimage就是这样一个工具

dfimage是一个alpine的镜像,启动的时候,通过将dockeR.sock映射到容器内部来运行,通常将这个操作做成别名

我们拿Nginx镜像试验下

先pull一个Nginx镜像,我这里之前有,就直接用了,接着通过上面提到的命令,别名一个dfimage命令

做好别名之后,通过dfimage去生成Nginx的DockeRfile,其实就是启动一个容器工具,执行完之后即删除

即可看到完整的DockeRfile

OpenMagic API

Need more than content? Move into the product flow.

If you are here for model access, pricing, developer docs, or the future API console, the dedicated product path now lives on api.openmagic.ai.

登录免费注册