日日操夜夜添-日日操影院-日日草夜夜操-日日干干-精品一区二区三区波多野结衣-精品一区二区三区高清免费不卡

公告:魔扣目錄網(wǎng)為廣大站長提供免費收錄網(wǎng)站服務(wù),提交前請做好本站友鏈:【 網(wǎng)站目錄:http://www.ylptlb.cn 】, 免友鏈快審服務(wù)(50元/站),

點擊這里在線咨詢客服
新站提交
  • 網(wǎng)站:52000
  • 待審:37
  • 小程序:12
  • 文章:1037587
  • 會員:756


Nginx 指定容器名稱 使用 ctr contAIner create 命令創(chuàng)建容器后,容器并沒有處于運行狀態(tài),其只是一個靜態(tài)的容器。

容器基本操作

容器基本操作主要是 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

創(chuàng)建靜態(tài)容器

create:

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

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

查看容器

[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

容器任務(wù)

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

1.靜態(tài)容器啟動為動態(tài)容器

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

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

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

2.查看容器進程

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

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

通過ps 查看,其中第一個 PID 23181 就是我們?nèi)萜髦械?1 號進程。

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

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

[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參數(shù) 為 exec 進程設(shè)定一個id,可以隨意輸入,只要保證唯一即可,也可使用$RANDOM變量。

4.運行一個動態(tài)容器

[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類型網(wǎng)絡(luò))

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 href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

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

暫停容器進程

和 docker pause 類似的功能:

[root@localhost ~]# ctr task pause nginx

暫停后容器狀態(tài)變成了 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

刪除進程

殺掉容器后可以看到容器的狀態(tài)變成了 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 相關(guān)信息,可以使用 task metrics 命令用來獲取容器的內(nèi)存、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

分享到:
標簽:容器
用戶無頭像

網(wǎng)友整理

注冊時間:

網(wǎng)站:5 個   小程序:0 個  文章:12 篇

  • 52000

    網(wǎng)站

  • 12

    小程序

  • 1037587

    文章

  • 756

    會員

趕快注冊賬號,推廣您的網(wǎng)站吧!
最新入駐小程序

數(shù)獨大挑戰(zhàn)2018-06-03

數(shù)獨一種數(shù)學游戲,玩家需要根據(jù)9

答題星2018-06-03

您可以通過答題星輕松地創(chuàng)建試卷

全階人生考試2018-06-03

各種考試題,題庫,初中,高中,大學四六

運動步數(shù)有氧達人2018-06-03

記錄運動步數(shù),積累氧氣值。還可偷

每日養(yǎng)生app2018-06-03

每日養(yǎng)生,天天健康

體育訓練成績評定2018-06-03

通用課目體育訓練成績評定