Docker基礎和常用命令( 二 )


容器的實質是進程 , 但與直接在宿主執行的進程不同,容器進程運行于屬于自己的獨立的 命名空間 。因此容器可以擁有自己的 root 文件系統、自己的網絡配置、自己的進程空間,甚至自己的用戶 ID 空間 。容器內的進程是運行在一個隔離的環境里,使用起來,就好像是在一個獨立于宿主的系統下操作一樣 。
容器和鏡像一樣都是使用分層存儲,每一個容器運行時,是以鏡像為基礎層,在其上創建一個當前容器的存儲層,我們可以稱這個為容器運行時讀寫而準備的存儲層為容器存儲層 。
2.3 , 倉庫鏡像構建完成后 , 可以很容器的在當前宿主主機上運行,但是如果需要在其他服務器上使用這個鏡像,我們就需要一個集中的存儲、分發鏡像的服務,Docker Registry 就是這樣的服務 。
一個 Docker Registry 中可以包含多個 倉庫(Repository);每個倉庫可以包含多個 標簽(Tag);每個標簽對應一個鏡像 。
通常,一個倉庫會包含同一個軟件不同版本的鏡像,而標簽就常用于對應該軟件的各個版本 。我們可以通過 <倉庫名>:<標簽> 的格式來指定具體是這個軟件哪個版本的鏡像 。如下所示:
registry.sensetime.com/kestrel_tatraffic/kestrel_tatraffic:kestrel_cuda11_1.2.21_opencv3.4.13_with_ffmpeg
Docker倉庫(Registry) 分為公開倉庫(Public)和私有倉庫(Private)兩種形式 。最大的公開倉庫是 Docker Hub ,  存放了數量龐大的鏡像供用戶下載 。國內的公開倉庫包括 Docker Pool 等 , 可以提供大陸用戶更穩定快速的訪問 。私有倉庫是指用戶在本地搭建的私有 Docker Registry 。
三,Docker 使用3.1,Docker 服務安裝 Docker 這里不做介紹 。以下是 Linux 系統下,一些 docker 使用命令:
1,查看 Docker 服務狀態:使用 systemctl status docker 命令查看 Docker 服務的狀態 。其中 Active: active (running) 即表示 Docker 服務為正在運行狀態 。

Docker基礎和常用命令

文章插圖
2 , 停止 Docker 服務:使用 systemctl stop docker 命令 。
3,啟動 Docker 服務:使用 systemctl start docker 命令 。
4,重啟 Docker 服務:使用 systemctl restart docker 命令 。
5,測試 Docker 是否安裝正確 。
$ docker run --rm hello-worldUnable to find image 'hello-world:latest' locallylatest: Pulling from library/hello-world7050e35b49f5: Pull completeDigest: sha256:13e367d31ae85359f42d637adf6da428f76d75dc9afeb3c21faea0d976f5c651Status: Downloaded newer image for hello-world:latestHello from Docker!This message shows that your installation appears to be working correctly.To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.(arm64v8) 3. The Docker daemon created a new container from that image which runs theexecutable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent itto your terminal.To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bashShare images, automate workflows, and more with a free Docker ID: https://hub.docker.com/For more examples and ideas, visit: https://docs.docker.com/get-started/3.2 , 下載與使用Docker公共鏡像(Images)1,使用 docker search 命令從 Docker Repo 搜索 Dokcer 可用的鏡像 。示例命令:docker search ubuntu18.04 。
Docker基礎和常用命令

文章插圖
2,使用 docker image pull 命令從 Docker Repo 獲取指定的 Dokcer鏡像(Images) 。示例命令: docker image pull docker.io/hello-world 。拉取名為 docker.io/hello-world 的鏡像 。
Docker基礎和常用命令

文章插圖
3,使用 docker image ls 命令查看本地的 Dokcer 鏡像(Images) 。
4,使用 docker run 命令運行 Dokcer 鏡像(Images) 。示例命令:docker run hello-world 。
Docker基礎和常用命令

文章插圖
5,使用 docker info 命令,查看當前 docker容器 的所有的信息 。
Docker基礎和常用命令

文章插圖
6,使用 docker version 查看容器的版本信息 。
$ dockerd --versio # 這個命令查看 docker 版本更簡單Docker version 19.03.13, build 4484c46d9d
Docker基礎和常用命令

推薦閱讀