學習使用podman建立最簡單的鏡像執行個體helloword,參考docker的相關執行個體代碼
podman build 使用一個或多個容器檔案或Docker檔案以及指定的建構上下文目錄中的說明建構映像。Containerfile在内部使用與Dockerfile相同的文法。在本文檔中,稱為容器檔案的檔案可以是名為‘Containerfile’或‘Dockerfile’的檔案。
參考
Podman-Build-使用容器檔案建構容器鏡像
【docker】docker建立最簡單最小的helloworld鏡像
Docker Dockerfile
推薦一個極其輕量級的 Docker 基礎鏡像,大小 2MB
podman指令使用和使用者配置
Docker 建構鏡像(docker build)
docker指令:拉取完docker鏡像後,如何檢視該鏡像的dockerfile檔案内容
docker鏡像逆向Dockerfile
docker鏡像建立、導入和導出(利用Dockerfile)
編譯與反編譯 GCC 常用指令
gcc 編譯和反編譯
操作
# podman 别名為 docker
alias docker=podman
官方hello使用及解析
# 拉取鏡像
podman pull docker.io/library/hello-world
# docker.io/library/hello-world latest feb5d9fea6a5 9 months ago 19.9 kB
# 指令docker history來通過檢視分層的方式嘗試确定更改過的地方
podman history feb5d9fea6a5
docker history --format {{.CreatedBy}} --no-trunc=true feb5d9fea6a5 |sed "s/\/bin\/sh\ -c\ \#(nop)\ //g"|sed "s/\/bin\/sh\ -c/RUN/g" | tac
# 鏡像導出
docker save -o hello.tar hello-world:latest
![](https://img.laitimes.com/img/9ZDMuAjOiMmIsIjOiQnIsIyZuBnLmZ2N3UDZ3gzMkNWM0kDZ5MTZyQTM5YGOyEGNkNWZxkzLc52YucWbp5GZzNmLn9Gbi1yZtl2Lc9CX6MHc0RHaiojIsJye.png)
hello.tar内容
[
{
"Config": "feb5d9fea6a5e9606aa995e879d862b825965ba48de054caab5ef356dc6b3412.json",
"RepoTags": [
"docker.io/library/hello-world:latest"
],
"Layers": [
"e07ee1baac5fae6a26f30cabfe54a36d3402f96afda318fe0a96cec4ca393359.tar"
]
}
]
{
"architecture": "amd64",
"config": {
"Hostname": "",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"/hello"
],
"Image": "sha256:b9935d4e8431fb1a7f0989304ec86b3329a99a25f5efdc7f09f3f8c41434ca6d",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": null
},
"container": "8746661ca3c2f215da94e6d3f7dfdcafaff5ec0b21c9aff6af3dc379a82fbc72",
"container_config": {
"Hostname": "8746661ca3c2",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"/bin/sh",
"-c",
"#(nop) ",
"CMD [\"/hello\"]"
],
"Image": "sha256:b9935d4e8431fb1a7f0989304ec86b3329a99a25f5efdc7f09f3f8c41434ca6d",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {}
},
"created": "2021-09-23T23:47:57.442225064Z",
"docker_version": "20.10.7",
"history": [
{
"created": "2021-09-23T23:47:57.098990892Z",
"created_by": "/bin/sh -c #(nop) COPY file:50563a97010fd7ce1ceebd1fa4f4891ac3decdf428333fb2683696f4358af6c2 in / "
},
{
"created": "2021-09-23T23:47:57.442225064Z",
"created_by": "/bin/sh -c #(nop) CMD [\"/hello\"]",
"empty_layer": true
}
],
"os": "linux",
"rootfs": {
"type": "layers",
"diff_ids": [
"sha256:e07ee1baac5fae6a26f30cabfe54a36d3402f96afda318fe0a96cec4ca393359"
]
}
}
編寫最小hello鏡像
内容來源 :【docker】docker建立最簡單最小的helloworld鏡像
mkdir build
# 編寫一個c源檔案hello.c
vim hello.c
# 編寫Dockerfile或Containerfile
vim build/Dockerfile
#vim build/Containerfile
# 改成podman的檔案也是可以的
# mv ./build/Dockerfile ./build/Containerfile
hello.c
内容
#include <sys/syscall.h>
void _start() {
syscall(SYS_write, 1, "hello podman.by zyl\n", sizeof("hello podman.by zyl\n") - 1);
syscall(SYS_exit, 0);
}
Dockerfile
或
Containerfile
内容
FROM scratch
COPY hello /
CMD ["/hello"]
編譯并打包
# gcc 編譯,最小檔案方式
gcc -static -Os -nostartfiles -fno-asynchronous-unwind-tables -o build/hello hello.c
# podman 或 docker 打包鏡像
docker build -t hello-podman:1.0 ./build/
# 運作
docker run -t hello-podman:1.0
# 檢視運作狀态
docker ps -a
移除鏡像
docker rm 18c2dd027373
docker rmi c419435568cd
docker ps -a