1. 程式人生 > 其它 >Kotlin中for in迴圈遍歷範圍

Kotlin中for in迴圈遍歷範圍

幫助命令

docker version #顯示docker版本資訊
docker info#顯示docker的系統資訊,包括映象和容器的數量
docker 命令 --help#萬能命令

幫助文件地址:https://docs.docker.com/
下列介紹的所有命令,如果對其使用或者可選項感興趣,均可以通過docker 命令 --help查詢資訊,也可以進入幫助文件檢視更詳細的資訊。

映象命令

docker images
#REPOSITORY 映象的倉庫源
#TAG 映象的標籤
#IMAGE ID 映象的id
#CREATED 建立時間
# 可選項
-a  --all #列出所有映象
-q --quiet #只顯示映象的id

docker images檢視所有本地的主機上的映象
在這裡插入圖片描述
docker search 搜尋映象
在這裡插入圖片描述

Options:
  -f, --filter filter   Filter output based on conditions provided
      --format string   Pretty-print search using a Go template
      --limit int       Max number of search results (default 25)
      --no-trunc        Don't truncate output
 # --filter=STARS=3000 搜尋出來的映象就是STARS不小於3000的
[email protected]:~$ docker search mysql --filter=STARS=3000
NAME      DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
mysql     MySQL is a widely used, open-source relation…   10583     [OK]
mariadb   MariaDB Server is a high performing open sou…   3960      [OK]

docker pull 下載映象

如果不指定下載版本,則該命令預設下載最新版本的映象。

docker pull mirrorname #下載預設映象
docker pull mirrorname[:tag]#下載指定版本映象(注意冒號不能省略)
[email protected]:~$ docker pull mysql
Using default tag: latest
latest: Pulling from library/mysql
a076a628af6f: Pull complete #分層下載,docker image的核心:聯合檔案資訊
f6c208f3f991: Pull complete
88a9455a9165: Pull complete
406c9b8427c6: Pull complete
7c88599c0b25: Pull complete
25b5c6debdaf: Pull complete
43a5816f1617: Pull complete
1a8c919e89bf: Pull complete
9f3cf4bd1a07: Pull complete
80539cea118d: Pull complete
201b3cad54ce: Pull complete
944ba37e1c06: Pull complete
Digest:
sha256:feada149cb8ff54eade1336da7c1d080c4a1c7ed82b5e320efb5beebed85ae8c
#簽名
Status: Downloaded newer image for mysql:latest
docker.io/library/mysql:latest

分層下載的好處在於不同版本的映象下載不需要把所有內容下載下來,相同的內容則不需要下載,由不同版本映象共用。

[email protected]:~$ docker pull mysql:5.7
5.7: Pulling from library/mysql
a076a628af6f: Already exists
f6c208f3f991: Already exists
88a9455a9165: Already exists
406c9b8427c6: Already exists
7c88599c0b25: Already exists
25b5c6debdaf: Already exists
43a5816f1617: Already exists
1831ac1245f4: Pull complete
37677b8c1f79: Pull complete
27e4ac3b0f6e: Pull complete
7227baa8c445: Pull complete                                                                                             Digest: sha256:b3d1eff023f698cd433695c9506171f0d08a8f92a0c8063c1a4d9db9a55808df
Status: Downloaded newer image for mysql:5.7
docker.io/library/mysql:5.7

docker rmi 刪除映象

docker rmi -f 容器id #刪除指定的容器
docker rmi -f  容器id 容器id 容器id #刪除多個容器

容器命令

有了映象才可以建立容器,在此下載centos映象來測試
(映象和容器的關係可以理解成映象是光碟,而容器是光碟上裝載的軟體)

docker pull centos
[email protected]:~$ docker pull centos
Using default tag: latest
latest: Pulling from library/centos
7a0437f04f83: Pull complete
Digest: sha256:5528e8b1b1719d34604c87e11dcd1c0a20bedf46e83b5632cdeac91b8c04efc1
Status: Downloaded newer image for centos:latest
docker.io/library/centos:latest

新建容器並啟動

 引數說明
--name="Name" 容器名字 tomcat01 tomcat02,用於區分容器
-d                       後臺方式執行
-it                       使用互動方式執行,進入容器檢視內容
-p                       指定容器的埠
#啟動並進入容器
[email protected]:~$ docker run -it centos /bin/bash
[[email protected] /]# 
#退出命令
exit
#從容器退回主機
docker ps # 檢視正在執行的容器
docker ps -a #檢視執行過的容器
-n=? #顯示最近建立得容器
-aq #只顯示容器編號

[email protected]:~$ docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
[email protected]:~$ docker ps -a
CONTAINER ID   IMAGE                                               COMMAND       CREATED             STATUS                         PORTS     NAMES
20c265a6694b   centos                                              "/bin/bash"   2 minutes ago       Exited (0) 44 seconds ago                happy_galois
6680c828adeb   hello-world                                         "/hello"      About an hour ago   Exited (0) About an hour ago             adoring_elbakyan
81a39d1a5f89   registry.cn-shanghai.aliyuncs.com/bianyuwei/byw:3   "sh run.sh"   2 days ago          Exited (1) 2 days ago                    nostalgic_napier
aef78050538c   registry.cn-shanghai.aliyuncs.com/bianyuwei/byw:2   "sh run.sh"   2 days ago          Exited (1) 2 days ago                    competent_noyce

退出容器

exit #直接停止並退出容器
Ctrl + P + Q #容器不停止退出

刪除容器

docker rm 容器id

啟動和停止容器的操作

docker start 容器id  #啟動容器
docker restart 容器id #重啟容器
docker stop 容器id #停止當前正在執行的容器
docker kill 容器id #停止當前正在執行的容器

後臺執行的大坑

#命令 docker run -d 映象名!
#問題docker ps,發現後臺啟動的容器停止了

常見的坑:dockers容器使用後臺執行,就必須要有一個前臺程序,docker發現沒有應用,就會自動停止