Docker教程-01.安裝docker-ce-18.06


參考文章:http://www.runoob.com/docker/docker-tutorial.html

1.Docker簡介

1)Docker 是一個開源的應用容器引擎,基於 Go 語言 並遵從Apache2.0協議開源。
2)Docker 可以讓開發者打包他們的應用以及依賴包到一個輕量級、可移植的容器中,然后發布到任何流行的 Linux 機器上,也可以實現虛擬化。
3)容器是完全使用沙箱機制,相互之間不會有任何接口(類似 iPhone 的 app)
4)容器的性能開銷極低。

2.Docker的應用場景

1)Web 應用的自動化打包和發布。
2)自動化測試和持續集成、發布。
3)在服務型環境中部署和調整數據庫或其他的后台應用。
4)從頭編譯或者擴展現有的OpenShift或Cloud Foundry平台來搭建自己的PaaS環境。

3.Docker 的優點

1)簡化程序:

Docker 讓開發者可以打包他們的應用以及依賴包到一個可移植的容器中,然后發布到任何流行的 Linux 機器上,便可以實現虛擬化。
Docker改變了虛擬化的方式,使開發者可以直接將自己的成果放入Docker中進行管理。
方便快捷已經是 Docker的最大優勢,過去需要用數天乃至數周的任務,在Docker容器的處理下,只需要數秒就能完成。

2)避免選擇恐懼症:

Docker 鏡像中包含了運行環境和配置,所以 Docker 可以簡化部署多種應用實例工作。比如 Web 應用、后台應用、數據庫應用、大數據應用比如 Hadoop 集群、消息隊列等等都可以打包成一個鏡像部署。

3)節省開支:

雲計算時代到來,使開發者不必為了追求效果而配置高額的硬件,Docker 改變了高性能必然高價格的思維定勢。
Docker 與雲的結合,讓雲空間得到更充分的利用。不僅解決了硬件管理的問題,也改變了虛擬化的方式。

4.相關鏈接

Docker 官網:http://www.docker.com

Github Docker 源碼:https://github.com/docker/docker

5.docker-ce版本簡介

5.1.全稱:Docker Community Edition for CentOS

5.2.docker在更新為CE和EE版本之前的最新版本為docker-1.13,在1.13的基礎之上,從2017年的3月1號開始,版本的格式變為docker-YY.MM,如下:

docker-17.12.1-ce.tgz
stable版本    每個季度發行
edge版本      每個月發行

5.3.目前,Ubuntu和CentOS都支持docker的CE和EE版本,EE版本對安全方面進行了強化。

6.安裝docker-ce准備

6.1.docker-ce安裝方法:

1)配置docker倉庫進行yum安裝,升級等,官方推薦方式
2)下載RPM包手動安裝,適用於沒有網絡的安裝環境
3)源碼安裝,下載tgz源碼包編譯安裝
4)使用一些集成好的安裝腳本進行安裝,用於測試和開發環境快速部署

6.2.軟件版本

CentOS7.5_x86-64
docker-ce-18.06.1.ce

7.yum在線安裝docker-ce

# 建議上午安裝,晚上docker官網基本打不開

7.1.卸載舊版docker軟件

# 名稱一般為docker,docker-io或者docker-engine
# 卸載完成還需要查看並清理舊的docker數據目錄,包含鏡像,容器,網絡等配置

sudo yum remove docker docker-engine docker-common \
    docker-client docker-client-latest docker-latest docker-latest-logrotate \
    docker-logrotate docker-selinux docker-engine-selinux
rpm -qa |grep docker*
ll /var/lib/docker/

7.2.配置docker的yum倉庫

# 安裝依賴包

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

# 配置stable庫

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

# 就是這條命令,晚上很容易不成功

# 禁用edge和test庫

yum-config-manager --disable docker-ce-edge docker-ce-test
# yum-config-manager --enable docker-ce-edge docker-ce-test

# 備注:

1)yum-utils提供yum-config-manager和utility工具
2)lvm2和device-mapper-persistent-data提供devicemapper的存儲驅動
3)即使不使用edge庫或test庫也必須安裝
4)建議上午安裝,如果下載超時可以手動下載然后上傳到/etc/yum.repos.d/目錄
5)Note: Starting with Docker 17.06, stable releases are also pushed to the edge and test repositories.
6)如果啟用edge和test庫,yum安裝時會安裝最新版的docker,一般為test測試版,如果要安裝最新的穩定版需要禁用該選項

7.3.安裝docker-ce

# 查看可安裝的docker-ce列表

yum list docker-ce --showduplicates
# yum list docker-ce --showduplicates | sort -r    # 倒序排列

# 安裝最新版docker-ce

yum install docker-ce

# 要安裝指定版本docker,可以從上面的列表選擇對應的版本號

yum install docker-ce-<VERSION STRING>
yum install docker-ce-18.06.1.ce-3.el7

# 附:升級docker-ce

yum -y upgrade <包名>

# 注意:

1)如果提示需要接受GPGkey,需要與以下fingerprint匹配:
060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35
2)安轉完成會自動創建docker用戶組,需要手動創建docker用戶

7.4.啟動docker配置開機自啟動

systemctl start docker
systemctl enable docker
ps -ef |grep docker

7.5.檢查確認docker是否安裝成功

docker run hello-world

實例演示:

# 用docker運行一個名為hello-world的鏡像,顯示以下內容表示安裝正確

[root@docker-srv tools]# sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
9db2ca6ccae0: Pull complete 
Digest: sha256:4b8ff392a12ed9ea17784bd3c9a8b1fa3299cac44aca35a85c90c5e3c7afacdc
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/engine/userguide/

8.離線安裝docker-ce

# 使用RPM包進行安裝

RPM包下載地址:
https://download.docker.com/linux/centos/7/x86_64/stable/Packages/

8.1.下載docker-ce的rpm包

mkdir -p /server/tools
cd /server/tools
wget https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-18.06.1.ce-3.el7.x86_64.rpm

8.2.安裝docker-ce

yum install docker-ce-18.06.1.ce-3.el7.x86_64.rpm

8.3.啟動docker配置開機自啟動

systemctl start docker
systemctl enable docker
ps -ef |grep docker

8.4.檢查docker安裝的正確性

docker run hello-world

9.使用docker腳本進行安裝 

# 注意:不可以用在生產環境

curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh

腳本內容:

<output truncated>

If you would like to use Docker as a non-root user, you should now consider
adding your user to the "docker" group with something like:

  sudo usermod -aG docker your-user

Remember to log out and back in for this to take effect!

WARNING: Adding a user to the "docker" group grants the ability to run
         containers which can be used to obtain root privileges on the
         docker host.
         Refer to https://docs.docker.com/engine/security/security/#docker-daemon-attack-surface
         for more information.

10.卸載清理docker-ce軟件 

10.1.卸載docker-ce軟件

yum remove docker-ce

10.2.清理docker-ce數據

rm -rf /var/lib/docker

======== 完畢,呵呵呵呵 ========


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM