Docker容器初體驗

weixin_34378969發表於2017-11-02
6242595-cdf564db81cb5dba.png
docker.png

1. What is Docker?

6242595-73900d92a9861959.png
Docker-Build_Ship_and_Run_Any_App_Anywhere.png

Wikipedia 定義:
Docker is a software technology providing containers, promoted by the company Docker, Inc. Docker provides an additional layer of abstraction and automation of operating-system-level virtualization on Windows and Linux. (Docker 是提供容器的軟體技術,在 Linux 上提供了作業系統級虛擬化的額外層次抽象和自動化。)

Docker is an open source project to pack, ship, and run any application as a lightweight container. (Docker 是一個開源專案,用於將任何應用程式作為輕型容器進行打包,運輸和執行。)

官方定義:
Docker is the world’s leading software containerization platform. (Docker 是軟體集裝箱化/容器化平臺)

Docker is the company driving the container movement and the only container platform provider to address every application across the hybrid cloud. (Docker 是解決跨混合雲的應用程式的唯一容器平臺提供商)

Docker 特性

  • agility-敏捷:13倍加速軟體開發和部署,並立即響應客戶需求
  • portability-可移植性:消除“在我這裡可以正常執行啊!”問題,一次打包隨處執行;通過內部和雲環境獲得獨立性
  • security-安全:通過內建的安全功能和配置,在整個生命週期內提供更安全的應用程式
  • cost savings-節約成本:優化基礎設施資源的使用和簡化操作,節省50%總成本

MODERN APP PLATFORM - 現代APP平臺

The Docker platform is the only container platform to build, secure and manage the widest array of applications from development to production both on premises and in the cloud. (Docker 平臺是唯一的容器平臺,用於構建、保護和管理應用程式,從開發到生產,在內部和雲中)

Docker 平臺特性

  • Simplicity-簡單:Docker 為應用程式建立和編排提供強大的工具
  • Openness-透明度:採用開源技術和模組化設計,可以輕鬆整合到現有的環境中
  • Independence-獨立:Docker 在開發人員和 IT 之間以及應用程式和基礎設施之間建立了分離關鍵點,以解鎖創新

Docker 平臺設計理念

  • DEVS:Docker 使開發人員更自由,更具創造力,更快地運送更多的軟體
  • OPS:通過跨所有容器化的應用程式和服務的通用控制平臺獲得可視性,管理和安全性
  • ECOSYSTEM-生態系統:Docker 是一個開放和可擴充套件的平臺,可輕鬆整合到現有環境中,促進全球科技,商業合作伙伴的充滿活力的生態系統

參考

2. 安裝並執行 Docker

在 Mac 上安裝 Docker,見 Install Docker for Mac

一、下載並安裝 Docker.dmg
二、執行 Docker

6242595-b6e70a60a8ddbd3c.png
docker-app-menu.png

Where to go next

  • Getting started provides an overview of Docker for Mac, basic Docker command examples, how to get help or give feedback, and links to all topics in the Docker for Mac guide.
  • Troubleshooting describes common problems, workarounds, how to run and submit diagnostics, and submit issues.
  • FAQs provides answers to frequently asked questions/為常見問題提供答案.
  • Release Notes lists component updates, new features, and improvements associated with Stable and Edge releases/羅列元件更新,新功能和改進.
  • Get Started with Docker provides a general Docker tutorial/提供一個通用的Docker教程.

3. 玩轉 Docker

跟著 Get started with Docker 開始使用 Docker。

6242595-b386ab64e4113fdf.png
engine-components-flow.png

3.1 檢查 Docker Engine/引擎, Compose/組裝, and Machine/機器的版本

➜  ~ docker --version
Docker version 17.09.0-ce, build afdb6d4
➜  ~ docker-compose --version
docker-compose version 1.16.1, build 6d1ac21
➜  ~ docker-machine --version
docker-machine version 0.12.2, build 9371605

3.2 探討應用和執行示例

3.2.1 執行一些Docker命令驗證Docker是否按預期工作

➜  ~ docker version
......
# Docker daemon 未啟動
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
➜  ~ docker version
# Docker 客戶端
Client:
 Version:      17.09.0-ce
 API version:  1.32
 Go version:   go1.8.3
 Git commit:   afdb6d4
 Built:        Tue Sep 26 22:40:09 2017
 OS/Arch:      darwin/amd64

# Docker 服務端版本,API版本,Go版本
Server:
 Version:      17.09.0-ce
 API version:  1.32 (minimum version 1.12)
 Go version:   go1.8.3
 Git commit:   afdb6d4
 Built:        Tue Sep 26 22:45:38 2017
 OS/Arch:      linux/amd64
 Experimental: true
➜  ~ docker ps
# 無容器執行中
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
➜  ~ docker run hello-world

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. (Docker客戶端聯絡Docker服務端守護程式)
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (Docker守護程式從Docker Hub拉取“hello-world”映象)
 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. (Docker守護程式從該映象建立一個新的容器,該容器執行可執行檔案,生成當前正在讀取的輸出)
 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. (Docker守護程式將輸出的流式內容傳輸到Docker客戶端,Docker客戶端將其傳送到您的終端)

Share images, automate workflows, and more with a free Docker ID/通過免費的Docker ID共享映象,自動化工作流程等:
 https://cloud.docker.com/

For more examples and ideas, visit/想了解更多示例和想法,請訪問:
 https://docs.docker.com/engine/userguide/

3.2.2 啟動容器化的Web伺服器

➜  ~ docker run -d -p 80:80 --name webserver nginx
122424b8077b791b42b31898eef3b77aa054a994b663fc832d5e90de430ac65a
# 啟動使用者態代理時出錯:80埠已使用
docker: Error response from daemon: driver failed programming external connectivity on endpoint webserver (0f305bfd15dcf2914f7bf2c815ed94412706f85e3a2d9d2e83ec7423d58a1726): Error starting userland proxy: Bind for 0.0.0.0:80: unexpected error (Failure EADDRINUSE).
➜  ~ docker run -d -p 80:80 --name webserver nginx
# 衝突:容器名稱"/webserver"已使用,您必須刪除(或重新命名)該容器才能重用該名稱
docker: Error response from daemon: Conflict. The container name "/webserver" is already in use by container "122424b8077b791b42b31898eef3b77aa054a994b663fc832d5e90de430ac65a". You have to remove (or rename) that container to be able to reuse that name.
See 'docker run --help'.
➜  ~ docker rm webserver
webserver

Nginx啟動正常:Networking features in Docker for Mac

➜  ~ docker run -d -p 8080:80 --name webserver nginx
# 容器ID
61a674b351579ccc527f13f679ace017147789ae667dc5ff0caa275add1e898f

在Web瀏覽器中,轉到 http://localhost:8080/ 開啟主頁。

3.2.3 檢視容器詳細資訊

➜  ~ docker ps
# 容器ID,映象名稱,執行命令,建立時間,執行狀態,埠對映,容器名稱
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMES
61a674b35157        nginx               "nginx -g 'daemon ..."   About an hour ago   Up About an hour    0.0.0.0:8080->80/tcp   webserver

3.2.4 停止或移除容器或映象

停止或啟動容器

➜  ~ docker stop webserver
webserver
➜  ~ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
➜  ~ docker start webserver
webserver
➜  ~ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMES
61a674b35157        nginx               "nginx -g 'daemon ..."   About an hour ago   Up 1 second         0.0.0.0:8080->80/tcp   webserver
➜  ~ docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                    PORTS                  NAMES
61a674b35157        nginx               "nginx -g 'daemon ..."   About an hour ago   Up 8 seconds              0.0.0.0:8080->80/tcp   webserver
cecc48eb752e        hello-world         "/hello"                 2 hours ago         Exited (0) 2 hours ago                           pedantic_almeida

停止並移除執行中的容器

➜  ~ docker rm -f webserver
webserver

列出本地映象

➜  ~ docker images
# 倉庫,標籤,映象ID,建立時間,映象大小
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               latest              c59f17fe53b0        6 days ago          108MB
alpine              latest              37eec16f1872        8 days ago          3.97MB
hello-world         latest              05a3bd381fc2        7 weeks ago         1.84kB

首選項

包括 General,File sharing,Advanced,HTTP proxy settings,Docker Daemon


6242595-45f2bd8b89dffb70.png
Preferences.png

新增TLS證書

安裝bash完成

提供反饋並獲得幫助

Docker Store

Docker store is a component of the next-generation Docker Hub, and the best place to find compliant, trusted commercial and free software distributed as Docker Images.

The Docker Store - Find Trusted and Enterprise Ready Containers, Plugins, and Docker Editions/查詢可信和企業就緒的容器、外掛和Docker版本

6242595-82030d95417b4f76.png
docker-store.png

Docker Cloud

Docker Cloud - Build, Ship and Run any App, Anywhere
The official cloud service for continuously delivering Docker applications.

  • Continuous integration (CI) for Docker/Docker持續整合
  • Fully-managed Docker Registry Service/完全託管的Docker註冊服務
  • Provision & manage Swarms/配置和管理叢集
6242595-fb07eacb04e7490e.png
docker-cloud.png

Where to go next

  • Try out the walkthrough/嘗試演練 at Get Started.
  • Dig in deeper with Docker Labs example walkthroughs and source code/深入挖掘Docker Labs的示例演練和原始碼.
  • For a summary of Docker command line interface (CLI) commands, see Docker CLI Reference Guide/有關Docker命令列介面(CLI)命令的摘要,見Docker命令列介面參考指南.
  • Check out the blog post/看看部落格文章 Introducing Docker 1.13.0.

祝玩得開心!ˇˍˇ
雲舒,2017.11.2,杭州

相關文章