1. 程式人生 > 實用技巧 >Docker深入學習1

Docker深入學習1

一.簡單說明

關於Docker是什麼,我們在博文的其它篇幅(https://www.cnblogs.com/yuhaohao/p/10150111.html)已經介紹過,這裡就不重複進行介紹,關於Docker的安裝,這裡我們在centos7的系統直接通過下面的命令安裝即可:

yum install -y docker
systemctl start docker 

二.Docker的基本操作

Docker的操作包含:

  • 容器映象操作
  • 容器及其中應用生命週期操作
  • 容器檔案系統操作
  • 容器卷(Volume)操作
  • 容器倉庫(Registry)操作
  • 容器網路操作
  • 容器系統操作

2.1 容器映象操作

# 映象操作:
build     Build an image from a Dockerfile(這裡是構建Docker映象操作)
commit    Create a new image from a container's changes(這裡是從一個執行的容器裡面,修改某些東西儲存為一個新的Docker映象)
images    List images(列出當前主機Docker映象)
load      Load an image from a tar archive or STDIN(匯入Docker映象)
pull      Pull an image or a repository from a registry(拉取Docker映象)
push      Push an image or a repository to a registry(推送Docker映象)
rmi       Remove one or more images(刪除一個或者多個Docker映象)
search    Search the Docker Hub for images(從Dockerhub上查詢Docker映象)
tag       Tag an image into a repository(將Docker映象更改TAG)
save      Save one or more images to a tar archive (streamed to STDOUT by default)(匯出一個或者多個Docker映象為tar包)
history   顯示某映象的歷史
inspect   獲取映象的詳細資訊

2.2 容器及其應用生命週期操作

# 容器及其中應用的生命週期操作:
create    Create a new container(建立一個容器)        
kill      Kill one or more running containers(殺掉一個或者多個執行的容器)
inspect   Return low-level information on a container, image or task(檢視執行的容器中的詳細資訊)
pause     Pause all processes within one or more containers(暫停一個或者多個容器)
ps        List containers(列出執行的容器,如果列出所有容器docker ps -a)
rm        Remove one or more containers(刪除一個或者多個容器)
rename    Rename a container(重新命名一個容器)
restart   Restart a container(重啟一個容器)
run       Run a command in a new container(建立並啟動一個容器)
start     Start one or more stopped containers(啟動一個處於停止狀態的容器)
stats     Display a live stream of container(s) resource usage statistics(顯示容器實時的資源消耗資訊)
stop      Stop one or more running containers(停止一個處於執行狀態的容器)
top       Display the running processes of a container(列出一個執行的容器中執行的程式)
unpause   Unpause all processes within one or more containers(繼續容器中的所有程序)
update    Update configuration of one or more containers(更新一個或者多個容器中的配置)
wait      Block until a container stops, then print its exit code(阻塞執行直到容器停止,然後打印出它的退出程式碼)
attach    Attach to a running container(連線到正在執行中的容器)
exec      Run a command in a running container(在執行的容器中執行命令)
port      List port mappings or a specific mapping for the container(列出指定的容器的埠對映,或者查詢將PRIVATE_PORT NAT到面向公眾的埠)
logs      獲取容器的日誌

2.3 容器檔案系統操作

cp        Copy files/folders between a container and the local filesystem(用於容器與主機之間的資料拷貝)
diff      Inspect changes on a container's filesystem(檢查容器裡檔案結構的更改)
export    Export a container's filesystem as a tar archive(將檔案系統作為一個tar歸檔檔案匯出到STDOUT)
import    Import the contents from a tarball to create a filesystem image(從歸檔檔案中建立映象)

2.4 Docker卷操作

在Docker中,如果想實現資料的持久化,需要將資料從宿主機掛載到容器中。目前

# Volume 操作
volume    Manage Docker volumes