当前位置: 首页 > wzjs >正文

网站开发时间进度表商城版网站制作

网站开发时间进度表,商城版网站制作,彩页设计费多少,深圳家居网站建设公司排名本文详细讲述完全从零开始手动创建一个可以被 docker load 加载的 Docker 镜像。我们将不使用 Docker 工具,直接构造符合 Docker 镜像格式(OCI 镜像规范)的 tar 文件。最终生成的镜像可以通过 docker load 导入到 Docker 中运行。 从零创建 D…

本文详细讲述完全从零开始手动创建一个可以被 docker load 加载的 Docker 镜像。我们将不使用 Docker 工具,直接构造符合 Docker 镜像格式(OCI 镜像规范)的 tar 文件。最终生成的镜像可以通过 docker load 导入到 Docker 中运行。


从零创建 Docker 镜像

Docker 镜像是一个 tar 包,包含文件系统层、配置文件和元数据。我们将创建一个简单的镜像,包含一个 shell 脚本,运行时输出 “Hello from my custom image!”。

步骤 1:准备文件系统层

创建一个简单的文件系统层,包含一个可执行的 shell 脚本。

  1. 创建工作目录和文件系统结构:
mkdir -p my-image/rootfs/bin
cd my-image
  1. 创建一个 shell 脚本:
echo -e '#!/bin/sh\necho "Hello from my custom image!"' > rootfs/bin/hello.sh
chmod +x rootfs/bin/hello.sh
  1. 打包文件系统层为 tar 文件:
tar -cvf layer.tar -C rootfs .

这会生成 layer.tar,包含文件系统内容(bin/hello.sh)。

步骤 2:创建镜像配置文件

需要一个 JSON 文件(config.json)来描述镜像的运行时配置。

my-image 目录下创建 config.json

{"architecture": "amd64","os": "linux","config": {"Entrypoint": ["/bin/hello.sh"],"Env": ["PATH=/bin"],"WorkingDir": "/"},"rootfs": {"type": "layers","diff_ids": []},"history": [{"created": "2025-04-19T00:00:00Z","created_by": "Manual creation"}]
}

计算层 diff_id

diff_ids 是文件系统层的 SHA256 校验值,格式为 sha256:<hash>。我们需要计算 layer.tar 的 SHA256 值。

运行以下命令:

sha256sum layer.tar

假设输出为:

e4d7f1b4...  layer.tar

sha256:e4d7f1b4... 添加到 config.jsonrootfs.diff_ids 中,更新 config.json

{"architecture": "amd64","os": "linux","config": {"Entrypoint": ["/bin/hello.sh"],"Env": ["PATH=/bin"],"WorkingDir": "/"},"rootfs": {"type": "layers","diff_ids": ["sha256:e4d7f1b4..."]},"history": [{"created": "2025-04-19T00:00:00Z","created_by": "Manual creation"}]
}

步骤 3:创建 Manifest 文件

manifest.json 描述镜像的层和配置信息。

my-image 目录下创建 manifest.json

[{"Config": "config.json","RepoTags": ["my-custom-image:latest"],"Layers": ["layer.tar"]}
]

步骤 4:打包镜像

将所有文件打包成一个 tar 文件,符合 Docker 镜像格式。

my-image 目录下运行:

tar -cvf my-image.tar manifest.json config.json layer.tar

这会生成 my-image.tar,即最终的 Docker 镜像文件。

步骤 5:验证和加载镜像

my-image.tar 传输到有 Docker 的环境中,运行:

docker load -i my-image.tar

加载后,检查镜像:

docker images

应该能看到 my-custom-image:latest

运行镜像:

docker run my-custom-image:latest

预期输出:

Hello from my custom image!

注意事项

  1. SHA256 计算:确保 layer.tar 的 SHA256 值正确,否则 Docker 会报错。
  2. 文件权限:确保 hello.sh 有可执行权限(chmod +x)。
  3. 架构兼容性architecture 字段需与目标运行环境匹配(这里使用 amd64)。
  4. 时间格式history.created 使用 ISO 8601 格式(YYYY-MM-DDTHH:MM:SSZ)。
  5. 依赖问题:此例中,hello.sh 依赖 /bin/sh。如果目标环境没有 /bin/sh,需要将 sh 二进制文件包含在 rootfs 中。

扩展:添加更多层

如果需要多个层,重复以下步骤:

  1. 创建新的文件系统目录,添加或修改文件。
  2. 打包成新的 layerN.tar
  3. 计算新层的 SHA256 值,添加到 config.jsondiff_ids
  4. manifest.jsonLayers 列表中添加新层。

例如,添加第二个层:

mkdir rootfs2
echo "Another file" > rootfs2/another.txt
tar -cvf layer2.tar -C rootfs2 .
sha256sum layer2.tar  # 假设得到 sha256:abcdef...

更新 config.json

"rootfs": {"type": "layers","diff_ids": ["sha256:e4d7f1b4...", "sha256:abcdef..."]
}

更新 manifest.json

"Layers": ["layer.tar", "layer2.tar"]

重新打包:

tar -cvf my-image.tar manifest.json config.json layer.tar layer2.tar

总结

通过以上步骤,你可以完全不依赖 Docker 工具,从零创建一个符合 OCI 规范的 Docker 镜像。最终的 my-image.tar 可以通过 docker load 导入并运行。此方法适用于需要深度定制镜像或在无 Docker 环境中构建镜像的场景。



文章转载自:

http://h85Xkf47.xbhpm.cn
http://HunzE6fm.xbhpm.cn
http://v4WYdoDk.xbhpm.cn
http://HpoVk9hk.xbhpm.cn
http://sIaG8m7c.xbhpm.cn
http://qlU0Ebbw.xbhpm.cn
http://i9X4pEDe.xbhpm.cn
http://tEDQHkTQ.xbhpm.cn
http://VRfjBobm.xbhpm.cn
http://u1aZQba8.xbhpm.cn
http://OQM28bCE.xbhpm.cn
http://B1czWjG3.xbhpm.cn
http://COogru3S.xbhpm.cn
http://naAcY8ip.xbhpm.cn
http://JBOMw7FR.xbhpm.cn
http://AqQAZyTE.xbhpm.cn
http://siqq5Tbq.xbhpm.cn
http://HUb11nyU.xbhpm.cn
http://ZTQOjevq.xbhpm.cn
http://HcRYB4yF.xbhpm.cn
http://KAyoSnTm.xbhpm.cn
http://DZpHZKde.xbhpm.cn
http://eBgSQcye.xbhpm.cn
http://VUrW87OA.xbhpm.cn
http://1Bw5lsWk.xbhpm.cn
http://C11MTgmg.xbhpm.cn
http://kRZQuMBn.xbhpm.cn
http://GLERO2OU.xbhpm.cn
http://04KCx6M0.xbhpm.cn
http://0b0HnEzr.xbhpm.cn
http://www.dtcms.com/wzjs/697419.html

相关文章:

  • 建站模板招募设计师网站开发颜色
  • ppt代做网站龙城建设网站公司
  • 八方建设集团有限公司网站手机软件分类
  • 英雄联盟网站建设北京注册公司代理机构
  • 做设计有必要买素材网站会员吗付费问答 WordPress
  • 网站建设的报价网站制作 符合百度
  • 网站网页切换怎么做教务管理系统官网
  • 财政局网站建设方案自学做网站一般要多久
  • 企业简介无锡seo代理
  • 眉山网站设计深圳怎么注册公司网站
  • 网站建设手机源码四川城乡建设厅建筑特种作业证书
  • 企业自建网站平台有哪些2018年主流网站开发语言
  • 制作网站需要的技术wordpress 教學
  • 有没有做丝网的网站呀深圳信用网官网
  • 做网站和做电脑软件差别大吗床品图案设计网站
  • 网站配资公司网站网站建设基本流程备案
  • 网站建设玖金手指排名11wordpress seo 优化
  • 有什么可以接单做设计的网站要做个公司网站的方案费用
  • 建设网站需要买什么建筑设计说明模板100字
  • 河南建筑业城乡建设网站查询外贸网站如何做的好
  • 在线教育网站流量是怎样做的有限公司破产后债务还用还吗
  • 青海省建设网站价格低怎么制作代码
  • 绵阳市建设局网站大连做网站比较好的公司
  • 网站搭建报价表wordpress图片页
  • 甘肃省住房和城乡建设部网站广州网站建设 seo
  • 结构设计网站推荐wordpress文章中显示打赏
  • 电子商务网站推广案例烟台网络公司哪家好
  • seo站长平台WordPress 发布内容
  • 优化网站收费标准电子工程网稳压器教程
  • 网件路由器刷机广东网站seo