nerdctl——替代docker、替代docker-compose

1. 下载地址

选择这个完整版,可以连containerd一起安装。

image.png

2. 安装

  • 解压缩得到一下四个目录
[root@liubei-02 nerdctl-full-1.0.0]# ll
drwxr-xr-x 2 root root      4096 10月 21 21:28 bin
drwxr-xr-x 3 root root        21 10月 21 21:27 lib
drwxr-xr-x 3 root root        17 10月 21 21:27 libexec
drwxr-xr-x 3 root root        17 10月 21 21:22 share

  • 拷贝二进制文件
cp ./bin/* /usr/local/bin
  • 拷贝启动文件
cp -ra ./lib/systemd/system/* /etc/systemd/system/
  • 启动和开机启动
# systemctl enable buildkit containerd 
# systemctl restart buildkit containerd 
# systemctl status buildkit containerd
  • cni 插件
[root@liubei-02 nerdctl-full-1.2.1]# makedir /opt/cni/bin
[root@liubei-02 nerdctl-full-1.2.1]# cp -ra ./libexec/cni/* /opt/cni/bin/

3 替代docker

和docker命令几乎相同,举几常用的命令做例子

  • 下载镜像
[root@liubei-02 nerdctl-full-1.2.1]# nerdctl pull harbocto.boe.com.cn/crow/crow-qin
harbocto.boe.com.cn/crow/crow-qin:latest:                                         resolved       |++++++++++++++++++++++++++++++++++++++|
manifest-sha256:5891ae5e691914196af46e869a6cba45c6e53266b4110b85c5c37385cc3b6b84: done           |++++++++++++++++++++++++++++++++++++++|
config-sha256:04f135a90290c42b8cf9b52395c04753b4d9ed48ddae7c714a0eccdf8acd9682:   done           |++++++++++++++++++++++++++++++++++++++|
layer-sha256:b042f1415af977fb7da4d48f6668fad99add49542a1e01eb14f52a5e55338e54:    done           |++++++++++++++++++++++++++++++++++++++|
layer-sha256:31603596830fc7e56753139f9c2c6bd3759e48a850659506ebfb885d1cf3aef5:    done           |++++++++++++++++++++++++++++++++++++++|
layer-sha256:b0faaf7e563984a940329fd6098b28ecec4309b30990df5b9f7f1618f7f585bf:    done           |++++++++++++++++++++++++++++++++++++++|
layer-sha256:3c6f0abee76a3b1cde1a485efdc7d2f09d2023c61736f6d862b23d94a3bd0f6e:    done           |++++++++++++++++++++++++++++++++++++++|
elapsed: 0.9 s                                                                    total:  17.7 M (19.6 MiB/s)
 
  • 查看镜像
[root@liubei-02 nerdctl-full-1.2.1]# nerdctl images
REPOSITORY                           TAG       IMAGE ID        CREATED           PLATFORM       SIZE         BLOB SIZE
harbocto.boe.com.cn/crow/crow-qin    latest    5891ae5e6919    34 seconds ago    linux/amd64    39.6 MiB     17.7 MiB
harbocto.boe.com.cn/public/mysql     5.7       9e02c7c9a87d    26 minutes ago    linux/amd64    428.5 MiB    143.5 MiB
  • 镜像打tag
[root@liubei-02 crow-qin]# nerdctl tag harbocto.boe.com.cn/crow/crow-qin harbocto.boe.com.cn/crow/crow-qin:0327
[root@liubei-02 crow-qin]# nerdctl images
REPOSITORY                           TAG       IMAGE ID        CREATED          PLATFORM       SIZE         BLOB SIZE
harbocto.boe.com.cn/crow/crow-qin    0327      5891ae5e6919    4 seconds ago    linux/amd64    39.6 MiB     17.7 MiB
harbocto.boe.com.cn/crow/crow-qin    latest    5891ae5e6919    4 hours ago      linux/amd64    39.6 MiB     17.7 MiB
harbocto.boe.com.cn/public/mysql     5.7       9e02c7c9a87d    4 hours ago      linux/amd64    428.5 MiB    143.5 MiB
  • 删除镜像
[root@liubei-02 crow-qin]# nerdctl rmi harbocto.boe.com.cn/crow/crow-qin:0327
Untagged: harbocto.boe.com.cn/crow/crow-qin:0327@sha256:5891ae5e691914196af46e869a6cba45c6e53266b4110b85c5c37385cc3b6b84
Deleted: sha256:89ae5c4ee501a09c879f5b58474003539ab3bb978a553af2a4a6a7de248b5740
Deleted: sha256:4e8c762c91062b88c9c07813b2cf0795d81401dd0fb0c19bed291901dd4f1cbd
Deleted: sha256:248001ffdc3a1a316501cd5b435bf6346fa6ddd88acecd90cff9cc08f5e2b3ed
Deleted: sha256:bbd2fde7f96c461ee59290dc20dc461036e1288f6e7e88c805aa2d1619c1c0c6
[root@liubei-02 crow-qin]# nerdctl images
REPOSITORY                           TAG       IMAGE ID        CREATED        PLATFORM       SIZE         BLOB SIZE
harbocto.boe.com.cn/crow/crow-qin    latest    5891ae5e6919    4 hours ago    linux/amd64    39.6 MiB     17.7 MiB
harbocto.boe.com.cn/public/mysql     5.7       9e02c7c9a87d    4 hours ago    linux/amd64    428.5 MiB    143.5 MiB

  • 启动容器
[root@liubei-02 ~]# nerdctl run -d -p 1840:1840 --name crow-qin harbocto.boe.com.cn/crow/crow-qin
b61ea892800e970b9a21279943342309b5b9496ff82a8fe8e50c9216b041ca94
  • 查看容器
CONTAINER ID    IMAGE                                       COMMAND        CREATED               STATUS    PORTS                     NAMES
b61ea892800e    harbocto.boe.com.cn/crow/crow-qin:latest    "/crow-qin"    About a minute ago    Up        0.0.0.0:1840->1840/tcp    crow-qin
  • 停止容器
[root@liubei-02 ~]# nerdctl stop crow-qin
crow-qin
[root@liubei-02 ~]# nerdctl ps -a
CONTAINER ID    IMAGE                                       COMMAND        CREATED          STATUS                       PORTS                     NAMES
b61ea892800e    harbocto.boe.com.cn/crow/crow-qin:latest    "/crow-qin"    2 minutes ago    Exited (2) 15 seconds ago    0.0.0.0:1840->1840/tcp    crow-qin
  • 删除容器
[root@liubei-02 ~]# nerdctl rm crow-qin
crow-qin
[root@liubei-02 ~]# nerdctl ps -a
CONTAINER ID    IMAGE    COMMAND    CREATED    STATUS    PORTS    NAMES

4. 替代docker-compose

  • docker-compose.yml文件如下
version: "3"
services:
  crow_qin:
    image: harbocto.boe.com.cn/crow/crow-qin
    ports:
      - 1840:1840
    restart: always
  • 启动容器
[root@liubei-02 crow-qin]# nerdctl compose up -d
INFO[0000] Creating network crow-qin_default
INFO[0000] Ensuring image harbocto.boe.com.cn/crow/crow-qin
INFO[0000] Creating container crow-qin_crow_qin_1
  • 查看结果
[root@liubei-02 crow-qin]# nerdctl ps
CONTAINER ID    IMAGE                                       COMMAND        CREATED           STATUS    PORTS                     NAMES
a0ebebf7bb9d    harbocto.boe.com.cn/crow/crow-qin:latest    "/crow-qin"    12 seconds ago    Up        0.0.0.0:1840->1840/tcp    crow-qin_crow_qin_1
  • 查看日志
[root@liubei-02 crow-qin]# nerdctl compose logs -f
crow_qin_1 |&{MysqlConf:{MysqlIp:10.10.239.136 MysqlPort:3306 DbName:crow MysqlUser:root MysqlPassword:1234} RedisConf:{RidesIp:10.10.239.136 RidesPort:6379 RidesDbNum:2 RidesPassword:""}}
crow_qin_1 |2023-03-27 13:40:48.649648 INFO config/connect_mysql.go:48 数据库链接成功
crow_qin_1 |2023-03-27 13:40:48.649728 INFO config/connect_redis.go:19 Redis<10.10.239.136:6379 db:2>
crow_qin_1 |2023-03-27 13:40:48.650863 INFO cache/example.go:51 OK
crow_qin_1 |2023-03-27 13:40:48.650873 INFO cache/example.go:53 redis 链接成功
crow_qin_1 |OK
crow_qin_1 |[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.
crow_qin_1 |
crow_qin_1 |[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
crow_qin_1 | - using env:       export GIN_MODE=release
crow_qin_1 | - using code:      gin.SetMode(gin.ReleaseMode)
crow_qin_1 |
crow_qin_1 |[GIN-debug] GET    /swagger/*any             --> github.com/swaggo/gin-swagger.CustomWrapHandler.func1 (3 handlers)
crow_qin_1 |[GIN-debug] GET    /api/v1/ping              --> crow-qin/src/router.Ping (3 handlers)
crow_qin_1 |[GIN-debug] GET    /api/v1/version           --> crow-qin/src/router.Version (3 handlers)
crow_qin_1 |[GIN-debug] GET    /api/v1/liubei            --> crow-qin/src/router.LiuBei (3 handlers)
crow_qin_1 |[GIN-debug] POST   /api/v1/login             --> crow-qin/src/router.Login (3 handlers)
crow_qin_1 |[GIN-debug] POST   /api/v1/login/refresh     --> crow-qin/src/router.Refresh (3 handlers)
crow_qin_1 |[GIN-debug] POST   /api/v1/admin/user        --> crow-qin/src/router.CreateUser (4 handlers)
crow_qin_1 |[GIN-debug] PUT    /api/v1/admin/user-password --> crow-qin/src/router.ResetUserPassword (4 handlers)
crow_qin_1 |[GIN-debug] GET    /api/v1/admin/users       --> crow-qin/src/router.GetUsers (4 handlers)
crow_qin_1 |[GIN-debug] GET    /api/v1/admin/users/:uuid --> crow-qin/src/router.GetUser (4 handlers)
crow_qin_1 |[GIN-debug] DELETE /api/v1/admin/users/:uuid --> crow-qin/src/router.DeleteUser (4 handlers)
crow_qin_1 |[GIN-debug] PUT    /api/v1/admin/users       --> crow-qin/src/router.UpdateUsersInfo (4 handlers)
crow_qin_1 |[GIN-debug] PUT    /api/v1/user/info         --> crow-qin/src/router.UpdateUserInfo (4 handlers)
crow_qin_1 |[GIN-debug] PUT    /api/v1/user/password     --> crow-qin/src/router.UpdateUserPassword (4 handlers)
crow_qin_1 |[GIN-debug] GET    /api/v1/user/info         --> crow-qin/src/router.GetUserInfo (4 handlers)
crow_qin_1 |[GIN-debug] GET    /                         --> crow-qin/src/router.ServerRouter.func1 (3 handlers)
crow_qin_1 |[GIN-debug] GET    /js/*filepath             --> github.com/gin-gonic/gin.(*RouterGroup).createStaticHandler.func1 (3 handlers)
crow_qin_1 |[GIN-debug] HEAD   /js/*filepath             --> github.com/gin-gonic/gin.(*RouterGroup).createStaticHandler.func1 (3 handlers)
crow_qin_1 |[GIN-debug] [WARNING] You trusted all proxies, this is NOT safe. We recommend you to set a value.
crow_qin_1 |Please check https://pkg.go.dev/github.com/gin-gonic/gin#readme-don-t-trust-all-proxies for details.
crow_qin_1 |[GIN-debug] Listening and serving HTTP on :1840
  • 关闭容器
[root@liubei-02 crow-qin]# nerdctl compose down
INFO[0000] Removing container crow-qin_crow_qin_1
INFO[0000] Removing network crow-qin_default

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 205,236评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 87,867评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,715评论 0 340
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,899评论 1 278
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,895评论 5 368
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,733评论 1 283
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,085评论 3 399
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,722评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 43,025评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,696评论 2 323
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,816评论 1 333
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,447评论 4 322
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,057评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,009评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,254评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,204评论 2 352
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,561评论 2 343

推荐阅读更多精彩内容