Docker系列文-----我們為什么要使用Docker?以及Docker的安裝與部署(1)
- 一.容器是什么?
- 我們為什么要使用容器呢?容器有什么好處?
- 容器有什么好處呢?
- Docker和VMware同樣是虛擬化,Docker優勢在哪?
- 二.在Centos8上安裝Docker:
- 一.預先操作:
- 二.卸載之前的Docker:
- 三.添加倉庫檔案:
- 四.添加倉庫檔案:
- 五.啟動Docker服務,并且設定docker開機啟動
- 六.測驗運行一個docker容器
- 三.在Ubuntu系統上安裝Docker
- 一.卸載舊的docker
- 二.更新
- 三.添加docker官方的gpg密鑰
- 四.添加鏡像源
- 五.安裝
- 六.測驗
一.容器是什么?

Use containers to Build, Share and Run your applications
使用容器構建、共享和運行應用程式
簡單地說,一個容器包含了完整的運行時環境:除了應用程式本身之外,這個應用所需的全部依賴、類別庫、其他二進制檔案、組態檔等,都統一被打入了一個稱為容器鏡像的包中,通過將應用程式本身,和其依賴容器化,作業系統發行版本和其他基礎環境造成的差異,都不影響程式本身的運行,
我們為什么要使用容器呢?容器有什么好處?
大家都知道,在我們每個人的開發程序中,可能有一個代碼檔案(py或sh)在你的機器環境中無法運行,卻在別人的機器上一路暢通,那么代碼資料都是相同的,不同的就是機器的運行環境不同,而這一點在公司各部門之間的交接的時候,就會造成很大的問題,容器(Containers)便應運而生,
容器有什么好處呢?
一.靈活
同一個檔案可以在Linux、Windows、開發或測驗環境中都能運行
二.標準化
大多數容器實作技識訓于開放標準,可以運行在所有主流 的Linux 發行版、Microsoft等作業系統上,
容器鏡像提供版本控制,這樣就可以追蹤不同版本的容器,監控版本之間的差異,
三.安全性
一臺虛擬機上可以運行多個容器,可以隨時切換、開始、終止運行,但是容器之間互不影響,容器之間是相互隔離的,一個容器環境損壞并不影響其他容器,
Docker和VMware同樣是虛擬化,Docker優勢在哪?

如圖,簡單來說 Docker的啟動速度更快、消耗資源更少、拓展更加的方便,更高、更快、更強
如果想知道更多 可以前往Docker的官方網站進行了解 Docker官方網站點擊跳轉
二.在Centos8上安裝Docker:
一.預先操作:
1.設定自己用戶名為docker 方便與其他機器分辨
2.確保自己的系統Centos為Centos 8系統
[root@localhost ~]# hostnamectl set-hostname sc-docker
[root@localhost ~]# su -
上一次登錄:二 8月 10 23:33:43 CST 2021從 192.168.2.10pts/0 上
[root@sc-docker ~]#
[root@sc-docker ~]# cat /etc/centos-release
CentOS Linux release 8.3.2011
二.卸載之前的Docker:
\是續航符號:繼續到下一行
[root@sc-docker ~]# yum remove docker \
> docker-client \
> docker-client-latest \
> docker-common \
> docker-latest \
> docker-latest-logrotate \
> docker-logrotate \
> docker-engine
> --------------------------------------------------------
未找到匹配的引數: docker
未找到匹配的引數: docker-client
未找到匹配的引數: docker-client-latest
未找到匹配的引數: docker-common
未找到匹配的引數: docker-latest
未找到匹配的引數: docker-latest-logrotate
未找到匹配的引數: docker-logrotate
未找到匹配的引數: docker-engine
沒有軟體包需要移除,
依賴關系解決,
無需任何處理,
完畢!
三.添加倉庫檔案:
安裝yum-utils包(它提供yum-config-manager實用程式)并設定穩定存盤庫,
yum install -y yum-utils
添加docker官方的yum倉庫檔案,一會兒我們需要去docker官方的yum倉庫下載軟體
> [root@sc-docker ~]# yum-config-manager \
> --add-repo \
> https://download.docker.com/linux/centos/docker-ce.repo
添加倉庫自:https://download.docker.com/linux/centos/docker-ce.repo
我們可以選擇添加阿里云的國內鏡像docker倉庫,這樣下載速度會更快
> [root@sc-docker ~]# yum-config-manager \
> --add-repo \
> http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
添加倉庫自:http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
四.添加倉庫檔案:
[root@sc-docker yum.repos.d]# yum install docker-ce docker-ce-cli containerd.io -y
五.啟動Docker服務,并且設定docker開機啟動
[root@sc-docker yum.repos.d]# systemctl start docker
[root@sc-docker yum.repos.d]# systemctl enable docker
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.
六.測驗運行一個docker容器
[root@sc-docker yum.repos.d]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:df5f5184104426b65967e016ff2ac0bfcd44ad7899ca3bbcf8e44e4461491a9e
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.
(amd64)
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/
這一步結束后代表著Centos8的安裝成功了
三.在Ubuntu系統上安裝Docker
一.卸載舊的docker
sudo apt-get remove docker docker-engine docker.io containerd runc
二.更新
更新系統里的所有的能更新的軟體
sudo apt-get update
安裝相關的安裝包
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg \
lsb-release
三.添加docker官方的gpg密鑰
curl 是字符界面的瀏覽器、gpgkey 是用來驗證軟體的真偽—》防偽的
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
四.添加鏡像源
xiaoxiong@root:~$ echo \
> "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
> $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
五.安裝
添加鏡像源之后的更新apt-get
xiaoxiong@root:~$ sudo apt-get update
再安裝docker-ce這個軟體(下載程序可能比較慢)
sudo apt-get install docker-ce docker-ce-cli containerd.io -y
六.測驗
xiaoxiong@root:~$ sudo docker run hello-world
[sudo] password for xiaoxiong:
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:df5f5184104426b65967e016ff2ac0bfcd44ad7899ca3bbcf8e44e4461491a9e
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.
(amd64)
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/
這一步結束后代表著Ubuntu的安裝成功了

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/293282.html
標籤:其他
