華為云計算 云知識 Docker是什么
Docker是什么

簡介

Docker是一個開源的應(yīng)用容器引擎,讓開發(fā)者可以打包他們的應(yīng)用以及依賴包到一個可移植的 鏡像 中,然后發(fā)布到任何流行的Linux或Windows機器上,也可以實現(xiàn)虛擬化。容器是完全使用沙箱機制,相互之間不會有任何接口。

配置流程

Ubuntu操作系統(tǒng)

1. 準備環(huán)境

準備實例

從華為云官網(wǎng)購買鯤鵬云服務(wù)ECS實例

安裝依賴包

執(zhí)行以下命令安裝依賴包。

sudo apt-get update

sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common

2.執(zhí)行安裝

方式一:通過軟件倉庫安裝

1) 老版本的Docker的命名為“docker”、“docker.io” 或 “docker-engine”,如果安裝了這些版本,需要先卸載掉。

保存在“/var/lib/docker”/中的內(nèi)容,包括圖片、磁盤和網(wǎng)絡(luò)配置等都會保留下來。

sudo apt-get remove docker docker-engine docker.io containerd runc

2)添加Docker官方GPG key。

curl -fsSL https://download.docker.com/linux/ ubuntu /gpg | sudo apt-key add -

3)設(shè)置Docker CE軟件倉庫版本為arm64。

sudo add-apt-repository \
"deb [arch=arm64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"

4)安裝docker-ce軟件。

sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io

如果需要安裝指定版本的docker-ce,可以執(zhí)行以下命令:

sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io

方式二:下載軟件包進行安裝

1)通過https://download.docker.com/linux/ubuntu/dists/bionic/pool/stable/arm64/,下載指定版本的軟件包。

2)執(zhí)行命令安裝軟件包及依賴。

“package.deb”為下載的軟件包。

sudo dpkg -i /path/to/package.deb

3. 啟動軟件

1)啟動docker。

sudo systemctl start docker

2)使用一個hello-world鏡像驗證docker是否正常。

sudo docker run hello-world

回顯內(nèi)容如下:

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
3b4173355427: Pull complete 
Digest: sha256:41a65640635299bab090f783209c1e3a3f11934cf7756b09cb2f1e02147c6ed8
Status: Downloaded newer image for hello-world:latest
Hello 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 the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share 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/

CentOS操作系統(tǒng)

1.準備環(huán)境

準備實例

從華為云官網(wǎng)購買鯤鵬云服務(wù)ECS實例

安裝依賴包

執(zhí)行以下命令安裝依賴包。

sudo yum install -y yum-utils device-mapper-persistent-data lvm2

2.執(zhí)行安裝

方式一:使用軟件倉庫安裝

1)老版本的docker的命名為“docker”或 “docker-engine”,如果安裝了這些版本,需要先卸載掉。

保存在“/var/lib/docker/”中的內(nèi)容,包括圖片、磁盤和網(wǎng)絡(luò)配置等都會保留下來。

sudo yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate

2)配置軟件倉庫。

sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

3)     安裝docker-ce。

sudo yum install docker-ce docker-ce-cli containerd.io

這個命令總是會安裝最新版本的docker-ce,如果需要安裝指定版本的可以參考下面的操作:

sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io

方式二:下載軟件包進行安裝

1)通過https://download.docker.com/linux/centos/7/aarch64/stable/Packages/,下載指定版本的軟件包。

2)執(zhí)行命令安裝軟件包及依賴。

“package.rpm”為下載的軟件包。

sudo yum install /path/to/package.rpm

3. 啟動軟件

1)啟動Docker。

sudo systemctl start docker

2)使用一個hello-world鏡像驗證Docker是否正常。

sudo docker run hello-world

回顯內(nèi)容如下:

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
3b4173355427: Pull complete 
Digest: sha256:41a65640635299bab090f783209c1e3a3f11934cf7756b09cb2f1e02147c6ed8
Status: Downloaded newer image for hello-world:latest
Hello 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 the executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
docker run -it ubuntu bash
Share 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/