網站首頁 學習教育 IT科技 金融知識 旅遊規劃 生活小知識 家鄉美食 養生小知識 健身運動 美容百科 遊戲知識 綜合知識
當前位置:趣知科普吧 > IT科技 > 

dockerrun參數

欄目: IT科技 / 發佈於: / 人氣:5.98K

產品型號:Thinkpad E15

系統版本:centos8

docker命令教程

例1:執行一個 container並加載鏡像centos,執行起來這個實例後,在實例中執行 /bin/bash命令

docker常用參數:

dockerrun參數

run  執行

-i   以交互模式執行容器,通常與 -t 同時使用;

-t  爲容器重新分配一個僞輸入終端,通常與 -i 同時使用;

[root@xuegod63 ~]# docker images 

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

centos    latest              196e0ce0c9fb        12 days ago         196.6 MB

[root@xuegod63 ~]# docker run -it centos:latest bash  #啓動一個實例,也就2秒就可以搞定

[root@068fd8c70344 /]# ls   #檢視實例環境

[root@f072b5ae7542 /]# cat /etc/redhat-release 

退出容器:

[root@f072b5ae7542 /]#exit

例2:在 container 中啓動一個長久執行的進程,不斷向stdin輸出 hello world 。模擬一個後臺執行的服務

docker常用參數:

-d  後臺執行容器,並返回容器ID;

-c  後面跟待完成的命令

[root@xuegod63 ~]# docker run  -d centos:latest /bin/sh -c "while true;do echo hello world; sleep 1; done"

1b3493487c4fde6eb233d59fa9ab9a204ad993cd3debbd5a9a28be6816694605

#容器的ID

從一個容器中取日誌,檢視輸出的內容,可用於後期檢查docker實例在標準輸出中彈出的錯誤資訊或正常的資訊。 

語法: docker  logs   容器實例的Name/ID  

[root@xuegod63 ~]# docker logs 1b3493487c4    #容器的ID可以寫全,也可以不寫全,只要唯一就可以了

hello world

hello world

hello world

hello world

檢視正在執行的容器:

[root@xuegod63 ~]# docker ps  #列出所有執行中容器。

也可以使用短ID或docker實例的名字檢視日誌輸出:

[root@xuegod63 ~]# docker logs 4109c3446284

或:

[root@xuegod63 ~]# docker logs flamboyant_davinci

[root@xuegod63 ~]# docker ps -a  #-a 列出所有容器(包含沉睡/退出狀態的容器);

總結:

1、docker run -it centos:latest bash  啓動一個實例 

2、docker run  -d centos:latest /bin/sh -c "while true;do echo hello world; sleep 1; done"  #後臺執行容器,並返回容器ID;

3、docker  logs   容器實例的Name/ID從一個容器中取日誌,檢視輸出的內容

4、docker ps  #列出所有執行中容器。

Tags:dockerrun 參數