1. 下载地址
url
https://github.com/containerd/nerdctl/releases/选择安装包
选择这个完整版,可以连containerd一起安装。
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