国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 操作系統 > 正文

Docker -- 系統整潔之道 -- 1

2024-06-28 16:03:20
字體:
來源:轉載
供稿:網友

在上文Docker – 系統整潔之道 – 0中已經對Docker是什么,安裝Docker以及怎么運行一個簡單的容器有了初步了解,這篇文章介紹Docker的一些命令和Docker鏡像的使用及操作。

{% fi /images/201609/4.svg, Docker, Docker %}

一些Docker命令


Docker的命令按照使用一個容器的順序進行。

docker info 查看Docker的信息

~ docker infoContainers: 0Running: 0Paused: 0Stopped: 0Images: 8Server Version: 1.12.1Storage Driver: aufsRoot Dir: /var/lib/docker/aufs...

能查看到docker信息,說明docker是安裝好的。

docker run 運行一個容器

~ docker run -it Ubunturoot@8eac2e6cf194:/# lsbin boot dev etc home lib lib64 media mnt opt PRoc root run sbin srv sys tmp usr varroot@8eac2e6cf194:/#

由于在上文中已經運行過一次該條命令,所以ubuntu的鏡像已經下載到了本地,此次運行就可以使用該鏡像產生一個容器,在容器啟動后,上過-it獲取到命令行,運行命令ls

使用–name標志可以給容器定義一個名字,如 docker run –name this_is_first_ubunt_container -it ubuntu 就會創建一個名字叫做this_is_first_ubunt_container的ubuntu的容器。名字只能使用大小寫字母,數字,下劃線,原點和橫線,即[a-zA-Z0-9_.-]。

關于docker run的幫助可以使用docker run --help獲取。

docker ps 列出所有的容器

~ docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES8eac2e6cf194 ubuntu "/bin/bash" 5 minutes ago Up 5 minutes modest_davinci

使用docker ps命令可以看到當前正在運行的容器有哪些,并給出了一些相應的屬性。給命令增加參數-a就可以獲取當前所有的容器,包括已經停止的,如下。

~ docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES4d0cc9a960f1 hello-world "/hello" About a minute ago Exited (0) About a minute ago small_roentgen8eac2e6cf194 ubuntu "/bin/bash" 4 minutes ago Up 4 minutes modest_davinci

docker ps -n x,顯示最后x個容器,不管容器正在運行還是停止。

docker start 重新啟動已經停止的容器

docker start docker start this_is_first_ubunt_container

docker attatch 附著容器

docker attach this_is_first_ubunt_container

docker stop 停止一個容器

~ docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES4d0cc9a960f1 hello-world "/hello" 4 minutes ago Exited (0) 4 minutes ago small_roentgen8eac2e6cf194 ubuntu "/bin/bash" 8 minutes ago Up 8 minutes modest_davinci~ docker stop 8eac2e6cf1948eac2e6cf194~ docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES4d0cc9a960f1 hello-world "/hello" 4 minutes ago Exited (0) 4 minutes ago small_roentgen8eac2e6cf194 ubuntu "/bin/bash" 8 minutes ago Exited (0) 5 seconds ago modest_davinci

前幾個命令整體練習

創建一個有名字的container,停止它,啟動它。

~ docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES03248ab5d03b tomcat:latest "catalina.sh run" 2 days ago Exited (0) 2 days ago tomcat4d0cc9a960f1 hello-world "/hello" 4 days ago Exited (0) 4 days ago ~ docker run --name this_is_first_ubunt_container -it ubunturoot@894b1f0fa739:/# whoamirootroot@894b1f0fa739:/# exitexit~ docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES894b1f0fa739 ubuntu "/bin/bash" 21 seconds ago Exited (0) 14 seconds ago this_is_first_ubunt_container03248ab5d03b tomcat:latest "catalina.sh run" 2 days ago Exited (0) 2 days ago tomcat4d0cc9a960f1 hello-world "/hello" 4 days ago Exited (0) 4 days ago small_roentgen~ docker start 894b1f0fa739894b1f0fa739~ docker attach 894b1f0fa739root@894b1f0fa739:/# whoamirootroot@894b1f0fa739:/# exitexit~ docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES894b1f0fa739 ubuntu "/bin/bash" About a minute ago Exited (0) 8 seconds ago this_is_first_ubunt_container03248ab5d03b tomcat:latest "catalina.sh run" 2 days ago Exited (0) 2 days ago tomcat4d0cc9a960f1 hello-world "/hello" 4 days ago Exited (0) 4 days ago small_roentgen~ docker start this_is_first_ubunt_containerthis_is_first_ubunt_container~ docker attach this_is_first_ubunt_containerroot@894b1f0fa739:/# whoamirootroot@894b1f0fa739:/# exitexit

守護式容器

上面創建的ubuntu是交互式運行的容器(interactive container),也可以創建一個長期運行的容器–守護式容器(daemonized container)。

~ docker run --name daemon_ubuntu -d ubuntu /bin/sh -c "while true;do echo hello world;sleep 1;done"e56ae29adaf1d27cf49e05bccda5a7214be458fecc2afb0ff7721f16af8e044c~ docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESe56ae29adaf1 ubuntu "/bin/sh -c 'while tr" About a minute ago Up About a minute daemon_ubuntu

docker logs 容器日志

~ docker logs daemon_ubuntuhello worldhello worldhello worldhello world...~ docker logs --tail 0 -f daemon_ubuntuhello worldhello worldhello worldhello worldhello world

docker top 容器進程

~ docker top daemon_ubuntuPID USER TIME COMMAND2792 root 0:00 /bin/sh -c while true;do echo hello world;sleep 1;done3264 root 0:00 sleep 1

容器內運行進程

~ docker exec -d daemon_ubuntu touch /etc/new_config_file~ docker exec -it daemon_ubuntu /bin/sh# ls -l /etc | grep new-rw-r--r-- 1 root root 0 Oct 13 02:21 new_config_file

docker inspect 容器詳細信息

~ docker inspect daemon_ubuntu# 獲取容器運行狀態~ docker inspect --format='{{.State.Running}}' daemon_ubuntu# 查看容器ip地址~ docker inspect --format='{{.NetworkSettings.IPAddress}}' daemon_ubuntu

自動重啟容器

docker run –restart=always –name daemon_ubuntu -d ubuntu /bin/sh -c “while true;do echo hello world;sleep 1;done”

–restart=always 無論容器的退出代碼為何,都自動重啟。 –restart=on-failure 當容器退出代碼不為0時,自動重啟。 –restart=on-failure:5 重啟5次。

docker rm 刪除容器

運行中的Docker容器是無法刪除的。

# 刪除所有容器docker rm `docker ps -a -q`

Docker 鏡像

docker images

linux /var/lib/docker Mac $HOME/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/Docker.qcow2

docker pull ubuntu:16.10 獲取ubuntu倉庫中tag為16.10的鏡像。

docker pull -a ubuntu 獲取ubuntu倉庫中所有鏡像。

docker images ubuntu 列出本地所有ubuntu倉庫的鏡像。

docker run 的時候如果沒有指定鏡像的版本,則拉取最新版本進行創建。

Docker Hub 中倉庫分為兩種,一種是用戶倉庫(user repository),這種是用戶創建使用的的,命名方式為username/repositoryname,意義為用戶名/倉庫名;一種是頂層倉庫(top-repository),由docker內部人員管理。

docker search 查找Docker Hub上公用可用鏡像。

獲取鏡像時,格式其實可以看做 用戶/倉庫:標簽。 由于很多倉庫為官網所有,所有很多都變成了 倉庫:標簽,如上面寫的 ubuntu:16.10,ubutnu倉庫的tag為16.10的鏡像。

構建鏡像

docker commit docker build 和 Dockerfile文件

一般來說,我們不是真正「創建」了一個鏡像,而是基于一個已有的鏡像,構建了一個新的鏡像。

參考鏈接


Docker 從入門到實踐第一本Docker書一個比較詳細的命令用法
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 琼结县| 高清| 炉霍县| 彭泽县| 手游| 繁昌县| 德格县| 抚顺市| 丹江口市| 阆中市| 平乐县| 射阳县| 大兴区| 察哈| 东海县| 商城县| 深水埗区| 鄂伦春自治旗| 高唐县| 鄂尔多斯市| 呈贡县| 聊城市| 通渭县| 河东区| 广宁县| 和平区| 内丘县| 淳安县| 板桥市| 美姑县| 安泽县| 海原县| 台州市| 桑植县| 伊金霍洛旗| 肃北| 阜新| 正安县| 运城市| 重庆市| 乡宁县|