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

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

1.Docker簡介

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

2.Docker的應用場景

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

3.Docker 的優勢

1)簡化程序:

Docker 讓開發者能夠打包他們的應用以及依賴包到一個可移植的容器中,而後發佈到任何流行的 Linux 機器上,即可以實現虛擬化。
Docker改變了虛擬化的方式,使開發者能夠直接將本身的成果放入Docker中進行管理。
方便快捷已是 Docker的最大優點,過去須要用數天乃至數週的任務,在Docker容器的處理下,只須要數秒就能完成。github

2)避免選擇恐懼症:

Docker 鏡像中包含了運行環境和配置,因此 Docker 能夠簡化部署多種應用實例工做。好比 Web 應用、後臺應用、數據庫應用、大數據應用好比 Hadoop 集羣、消息隊列等等均可以打包成一個鏡像部署。docker

3)節省開支:

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

4.相關連接

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

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

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,以下:bash

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

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

相關文章
相關標籤/搜索