成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

容器運行時:Containerd容器管理

云計算 云原生
Nginx 指定容器名稱 使用 ctr container create 命令創建容器后,容器并沒有處于運行狀態,其只是一個靜態的容器。

容器基本操作

容器基本操作主要是 ctr image 命令,查看命令幫助:

[root@localhost ~]# ctr containers -h
NAME:
   ctr containers - Manage containers

USAGE:
   ctr containers command [command options] [arguments...]

COMMANDS:
   create                   Create container
   delete, del, remove, rm  Delete one or more existing containers
   info                     Get info about a container
   list, ls                 List containers
   label                    Set and clear labels for a container
   checkpoint               Checkpoint a container
   restore                  Restore a container from checkpoint

OPTIONS:
   --help, -h  show help

創建靜態容器

create:

[root@localhost ~]# ctr container create docker.io/library/nginx:alpine nginx

nginx 指定容器名稱 使用 ctr container create 命令創建容器后,容器并沒有處于運行狀態,其只是一個靜態的容器。這個 container 對象只是包含了運行一個容器所需的資源及配置的數據結構,例如:namespaces、rootfs 和容器的配置都已經初始化成功了,只是用戶進程(本案例為nginx)還沒有啟動。需要使用ctr tasks命令才能獲取一個動態容器。

查看容器

[root@localhost ~]# ctr container ls
CONTAINER    IMAGE                             RUNTIME                  
nginx        docker.io/library/nginx:alpine    io.containerd.runc.v2

加上 -q 選項 僅查看名字:

[root@localhost ~]# ctr container ls -q
nginx

也可以簡寫:

[root@localhost ~]# ctr c ls -q
nginx

查看容器詳細配置,類似于 docker inspect 功能。

[root@localhost ~]# ctr container info nginx

刪除容器

[root@localhost ~]# ctr container rm nginx
[root@localhost ~]# ctr container ls
CONTAINER    IMAGE    RUNTIME

容器任務

上面我們通過 container create 命令創建的容器,并沒有處于運行狀態,只是一個靜態的容器。一個 container 對象只是包含了運行一個容器所需的資源及相關配置數據,表示 namespaces、rootfs 和容器的配置都已經初始化成功了,只是用戶進程還沒有啟動。一個容器真正運行起來是由 Task 任務實現的,Task 可以為容器設置網卡,還可以配置工具來對容器進行監控等。我們操作容器實際上是對容器進程操作。

1.靜態容器啟動為動態容器

將靜態容器啟動為動態容器 ,使用 ctr task 命令 Task 相關操作可以通過 ctr task 獲取,如下我們通過 Task 來啟動容器:

[root@localhost ~]# ctr task start -d nginx

-d是一個命令行選項,它的全稱是--detach。這個選項告訴ctr task start命令在啟動任務后立即返回,讓任務在后臺運行。

2.查看容器進程

通過 task ls 查看正在運行的容器進程:

[root@localhost ~]# ctr task ls
TASK     PID      STATUS    
nginx    22945    RUNNING

通過ps 查看,其中第一個 PID 23181 就是我們容器中的 1 號進程。

[root@localhost ~]# ctr task ps nginx
PID      INFO
23181    -
23208    -

查看物理機進程,可以看到相應的進程ID:23181 、23208 可以對應的上:

[root@localhost ~]# ps -aux|grep nginx
root      23159  0.0  2.1 722644 20916 ?        Sl   13:01   0:00 /usr/local/bin/containerd-shim-runc-v2 -namespace default -id nginx -address /run/containerd/containerd.sock
root      23181  0.0  0.5   8904  5120 ?        Ss   13:01   0:00 nginx: master process nginx -g daemon off;
101       23208  0.0  0.2   9400  2256 ?        S    13:01   0:00 nginx: worker process
root      23266  0.0  0.2 112836  2332 pts/3    S+   13:15   0:00 grep --color=auto nginx

3.exec終端操作

[root@localhost ~]# ctr task exec --exec-id 0 -t nginx sh
/ # ls
bin                   docker-entrypoint.d   etc                   lib                   mnt                   proc                  run                   srv                   tmp                   var
dev                   docker-entrypoint.sh  home                  media                 opt                   root                  sbin                  sys                   usr
/ # pwd
/

這里要注意 --exec-id參數 為 exec 進程設定一個id,可以隨意輸入,只要保證唯一即可,也可使用$RANDOM變量。

4.運行一個動態容器

[root@localhost ~]# ctr run -d --net-host docker.io/library/nginx:alpine nginx2

[root@localhost ~]# ctr c ls
CONTAINER    IMAGE                             RUNTIME                  
nginx        docker.io/library/nginx:alpine    io.containerd.runc.v2    
nginx2       docker.io/library/nginx:alpine    io.containerd.runc.v2    

[root@localhost ~]# ctr task ls
TASK      PID      STATUS    
nginx     23181    RUNNING
nginx2    23339    RUNNING
  • -d 代表dameon,后臺運行
  • --net-host 代表容器的IP就是宿主機的IP(相當于docker里的host類型網絡)

5.進入容器

[root@localhost ~]# ctr task exec --exec-id 1 -t nginx2 /bin/sh
/ # ifconfig
eno16777736 Link encap:Ethernet  HWaddr 00:0C:29:AD:FC:E9  
          inet addr:192.168.36.137  Bcast:192.168.36.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fead:fce9/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2304427 errors:0 dropped:0 overruns:0 frame:0
          TX packets:462774 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:3259139229 (3.0 GiB)  TX bytes:182005861 (173.5 MiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:8 errors:0 dropped:0 overruns:0 frame:0
          TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:696 (696.0 B)  TX bytes:696 (696.0 B)

/ # curl 192.168.36.137
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a >nginx.org</a>.<br/>
Commercial support is available at
<a >nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

暫停容器進程

和 docker pause 類似的功能:

[root@localhost ~]# ctr task pause nginx

暫停后容器狀態變成了 PAUSED:

[root@localhost ~]# ctr task ls
TASK     PID      STATUS    
nginx    22945    PAUSED

恢復容器進程

使用 resume 命令來恢復容器:

[root@localhost ~]# ctr task resume nginx 
[root@localhost ~]# ctr task ls
TASK     PID      STATUS    
nginx    22945    RUNNING

殺死容器進程

ctr 沒有 stop 容器的功能,只能暫停或者殺死容器進程,然后在刪除容器殺死容器進程可以使用 task kill 命令:

[root@localhost ~]# ctr task kill nginx
[root@localhost ~]# ctr task ls
TASK     PID      STATUS    
nginx    22945    STOPPED

刪除進程

殺掉容器后可以看到容器的狀態變成了 STOPPED。同樣也可以通過 task rm 命令刪除 Task:

[root@localhost ~]# ctr task rm nginx
[root@localhost ~]# ctr task ls
TASK    PID    STATUS

刪除進程之后才可以刪除容器:

[root@localhost ~]# ctr c rm nginx

查看容器進程資源

除此之外我們還可以獲取容器的 cgroup 相關信息,可以使用 task metrics 命令用來獲取容器的內存、CPU 和 PID 的限額與使用量。

# 重新啟動容器
[root@localhost ~]# ctr task start -d nginx

[root@localhost ~]# ctr task metrics nginx
ID       TIMESTAMP                              
nginx    seconds:1701925304  nanos:694970440    

METRIC                   VALUE                                                                                                                                                                                                                                                                       
memory.usage_in_bytes    2592768                                                                                                                                                                                                                                                                     
memory.limit_in_bytes    9223372036854771712                                                                                                                                                                                                                                                         
memory.stat.cache        258048                                                                                                                                                                                                                                                                      
cpuacct.usage            21976291                                                                                                                                                                                                                                                                    
cpuacct.usage_percpu     [21976291 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]    
pids.current             2                                                                                                                                                                                                                                                                           
pids.limit               0
責任編輯:趙寧寧 來源: 云原生運維圈
相關推薦

2019-07-12 09:30:12

DashboardDockerDNS

2021-09-11 15:38:23

容器運行鏡像開放

2021-09-02 05:37:22

Containerd Kubernetes 容器

2023-08-29 08:20:35

Kubernete跨云容器

2023-01-03 09:10:21

2020-08-11 08:59:20

容器虛擬化技術

2021-10-22 00:09:16

Kubernetes容器接口

2021-03-24 06:26:00

kubeadmK8Scontainerd

2021-08-18 06:40:54

KubernetesDocker Containerd

2017-03-20 07:21:32

Docker

2021-12-23 07:58:06

Kubelet容器運行

2023-04-03 13:01:14

UbuntuCRI-O

2015-07-20 15:44:46

Swift框架MJExtension反射

2024-03-21 09:15:58

JS運行的JavaScrip

2024-04-15 05:00:00

kubernete網絡容器

2022-04-01 12:51:44

命令Containerd

2022-09-13 12:03:39

cri-dockerKubernetesdockershim

2021-09-07 07:48:37

kubeletKubernetesContainerd

2025-03-03 08:05:14

2022-02-16 20:04:08

容器KubernetesShim
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 国产精品国产精品国产专区不蜜 | 中文字幕一区二区不卡 | 欧美日韩国产一区二区 | 国产无人区一区二区三区 | hdfreexxxx中国妞 | 国产日韩欧美在线一区 | 水蜜桃久久夜色精品一区 | 色噜噜色综合 | 日韩三级 | 欧美极品视频 | 亚洲自拍偷拍视频 | 欧美视频中文字幕 | 9porny九色视频自拍 | av免费成人| 欧美日韩综合视频 | 国产精品美女久久久久久久久久久 | 成人久久久| 国产欧美日韩综合精品一区二区 | 免费黄色在线观看 | 亚洲精品乱 | 国产精品免费在线 | 欧美精品一区二区三区在线播放 | 五月槐花香 | 91看片官网 | 精品欧美乱码久久久久久 | 久久久久欧美 | 操久久 | 久久国产区 | 精品一区在线免费观看 | 精品视频在线观看 | 免费一二区| 中文字幕免费在线观看 | www.xxxx欧美| 天天色影视综合 | 欧美不卡视频 | 国产成人精品一区二三区在线观看 | 久久久久国产 | 一级黄色录像片子 | 午夜天堂精品久久久久 | 国产精品一区二区免费 | 久久伊人一区 |