学习使用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
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