Ubuntu安裝Docker 適合Ubuntu17.04版本


Docker介紹

Docker是一個開源的容器引擎,它有助於更快地交付產品。Docker可將應用程序和基礎設施層隔離,並且將基礎設施當作程序一樣進行管理。使用Docker,可以更快地打包,測試以及部署應用程序,並可以縮短從編程到部署運行代碼的周期。

Docker架構

  • Docker daemon

    守護進程,運行在宿主機(DOCKER_HOST)的后台進程,可通過Docker客戶端與之通信。

  • Client
    Docker客戶端時Docker的用戶界面,可以接受用戶命令和配置標識,並且Docker daemon通信

  • Images
    Docker鏡像是一個只讀模板,包含創建Docker容器的說明。Docker鏡像可以運行Docker鏡像中的程序。

  • Container
    容器是鏡像的可運行實例。鏡像與容器類似與面向對象中類與對象的關系。可通過Docker API或者CLI命令起停,移動,刪除等。

  • Register
    Docker Register是一個集中存儲與分發鏡像的服務。構建完Docker鏡像后,就可在當前宿主機上運行。但如果想在其他機器上運行這個鏡像,就需要手動復制。此時可以借助Docker Register避免復制。
    一個Docker Register可以包含多個Docker倉庫,每個倉庫可包含多個鏡像標簽,每個標簽對應一個Docker鏡像。

安裝Docker

其實開源的應用,官網都有正確的安裝教程(英文版),本章按照官網的教程安裝。

  1. 安裝倉庫

安裝Docker社區版倉庫

sudo apt-get -y install \ apt-transport-https \ ca-certificates \ curl
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ stable"
sudo apt-get update
××××××××××××××××××××××××××××××××××××××××××××××如果出現一下情況××××××××××××××××××××××××××××××××××××××××××××××××××

    出現這個問題可能是有另一個程序正在運行,導致資源被鎖不可用。而導致資源被鎖的原因可能是上次運行安裝或更新沒有正常完成,解決辦法就是刪掉。

    sudo rm /var/cache/apt/archives/lock

    sudo rm /var/lib/dpkg/lock

××××××××××××××××××××××××××××××××××××××××××××××××解決方案××××××××××××××××××××××××××××××××××××××××××××××××××××××××××
  1. 獲取Docker社區版

在Ubuntu上安裝最新的Docker社區版

sudo apt-get -y install docker-ce
  1. 測試你的Docker社區版是否安裝成功
sudo docker run hello-world

安裝后可查看版本

xq@xq-VPCEG17YC:/etc/apt/sources.list.d$ docker version Client: Version: 17.03.1-ce API version: 1.27 Go version: go1.7.5 Git commit: c6d412e Built: Mon Mar 27 17:14:09 2017 OS/Arch: linux/amd64

配置鏡像加速

sudo docker run hello-world的時候可能會出現timeout,應用國內訪問Docker Hub不穩定。建議改成阿里雲或者DaoCloud。本節以阿里雲為例。

注冊阿里雲賬戶

訪問https://cr.console.aliyun.com/#/accelerator

可以獲得自己的加速器 https://××××××.mirror.aliyuncs.com

echo "DOCKER_OPTS=\"--registry-mirror=https://××××××.mirror.aliyuncs.com\"" | sudo tee -a /etc/default/docker sudo service docker restart

安裝成功如下:

xq@xq-VPCEG17YC:/etc/docker$ echo "DOCKER_OPTS=\"--registry-mirror=https://××××××.mirror.aliyuncs.com\"" | sudo tee -a /etc/default/docker DOCKER_OPTS="--registry-mirror=https://bzf7wkv2.mirror.aliyuncs.com" xq@xq-VPCEG17YC:/etc/docker$ sudo service docker restart xq@xq-VPCEG17YC:/etc/docker$ sudo docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 78445dd45222: Pull complete Digest: sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7 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. 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://cloud.docker.com/ For more examples and ideas, visit: https://docs.docker.com/engine/userguide/


免責聲明!

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



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