Docker容器初體驗

docker.png

1. What is Docker?

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 是提供容器的軟件技術(shù)管跺,在 Linux 上提供了操作系統(tǒng)級虛擬化的額外層次抽象和自動化锁孟。)

Docker is an open source project to pack, ship, and run any application as a lightweight container. (Docker 是一個開源項目仗岸,用于將任何應(yīng)用程序作為輕型容器進行打包,運輸和運行揪惦。)

官方定義:
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 是解決跨混合云的應(yīng)用程序的唯一容器平臺提供商)

Docker 特性

  • agility-敏捷:13倍加速軟件開發(fā)和部署,并立即響應(yīng)客戶需求
  • portability-可移植性:消除“在我這里可以正常運行奥藓睢器腋!”問題,一次打包隨處運行钩杰;通過內(nèi)部和云環(huán)境獲得獨立性
  • security-安全:通過內(nèi)置的安全功能和配置纫塌,在整個生命周期內(nèi)提供更安全的應(yīng)用程序
  • cost savings-節(jié)約成本:優(yōu)化基礎(chǔ)設(shè)施資源的使用和簡化操作,節(jié)省50%總成本

MODERN APP PLATFORM - 現(xiàn)代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 平臺是唯一的容器平臺榜苫,用于構(gòu)建护戳、保護和管理應(yīng)用程序,從開發(fā)到生產(chǎn)垂睬,在內(nèi)部和云中)

Docker 平臺特性

  • Simplicity-簡單:Docker 為應(yīng)用程序創(chuàng)建和編排提供強大的工具
  • Openness-透明度:采用開源技術(shù)和模塊化設(shè)計媳荒,可以輕松集成到現(xiàn)有的環(huán)境中
  • Independence-獨立:Docker 在開發(fā)人員和 IT 之間以及應(yīng)用程序和基礎(chǔ)設(shè)施之間建立了分離關(guān)鍵點,以解鎖創(chuàng)新

Docker 平臺設(shè)計理念

  • DEVS:Docker 使開發(fā)人員更自由驹饺,更具創(chuàng)造力钳枕,更快地運送更多的軟件
  • OPS:通過跨所有容器化的應(yīng)用程序和服務(wù)的通用控制平臺獲得可視性,管理和安全性
  • ECOSYSTEM-生態(tài)系統(tǒng):Docker 是一個開放和可擴展的平臺赏壹,可輕松集成到現(xiàn)有環(huán)境中鱼炒,促進全球科技,商業(yè)合作伙伴的充滿活力的生態(tài)系統(tǒng)

參考

2. 安裝并運行 Docker

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

一昔瞧、下載并安裝 Docker.dmg
二、運行 Docker

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. 玩轉(zhuǎn) Docker

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

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 探討應(yīng)用和運行示例

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 服務(wù)端版本,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客戶端聯(lián)系Docker服務(wù)端守護進程)
 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守護進程從該鏡像創(chuàng)建一個新的容器酬荞,該容器運行可執(zhí)行文件搓劫,生成當前正在讀取的輸出)
 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. (Docker守護進程將輸出的流式內(nèi)容傳輸?shù)紻ocker客戶端,Docker客戶端將其發(fā)送到您的終端)

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服務(wù)器

?  ~ docker run -d -p 80:80 --name webserver nginx
122424b8077b791b42b31898eef3b77aa054a994b663fc832d5e90de430ac65a
# 啟動用戶態(tài)代理時出錯: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瀏覽器中咧党,轉(zhuǎn)到 http://localhost:8080/ 打開主頁秘蛔。

3.2.3 查看容器詳細信息

?  ~ docker ps
# 容器ID,鏡像名稱凿傅,運行命令缠犀,創(chuàng)建時間,運行狀態(tài)聪舒,端口映射辨液,容器名稱
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滔迈,創(chuàng)建時間,鏡像大小
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被辑,F(xiàn)ile sharing燎悍,Advanced,HTTP proxy settings盼理,Docker Daemon


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/查找可信和企業(yè)就緒的容器谈山、插件和Docker版本

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持續(xù)集成
  • Fully-managed Docker Registry Service/完全托管的Docker注冊服務(wù)
  • Provision & manage Swarms/配置和管理集群
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/有關(guān)Docker命令行界面(CLI)命令的摘要,見Docker命令行界面參考指南.
  • Check out the blog post/看看博客文章 Introducing Docker 1.13.0.

祝玩得開心宏怔!ˇ?ˇ
云舒奏路,2017.11.2,杭州

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末臊诊,一起剝皮案震驚了整個濱河市鸽粉,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌抓艳,老刑警劉巖触机,帶你破解...
    沈念sama閱讀 219,427評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異玷或,居然都是意外死亡儡首,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,551評論 3 395
  • 文/潘曉璐 我一進店門偏友,熙熙樓的掌柜王于貴愁眉苦臉地迎上來蔬胯,“玉大人,你說我怎么就攤上這事约谈”仕蓿” “怎么了?”我有些...
    開封第一講書人閱讀 165,747評論 0 356
  • 文/不壞的土叔 我叫張陵棱诱,是天一觀的道長泼橘。 經(jīng)常有香客問我,道長迈勋,這世上最難降的妖魔是什么炬灭? 我笑而不...
    開封第一講書人閱讀 58,939評論 1 295
  • 正文 為了忘掉前任,我火速辦了婚禮靡菇,結(jié)果婚禮上重归,老公的妹妹穿的比我還像新娘。我一直安慰自己厦凤,他們只是感情好鼻吮,可當我...
    茶點故事閱讀 67,955評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著较鼓,像睡著了一般椎木。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上博烂,一...
    開封第一講書人閱讀 51,737評論 1 305
  • 那天香椎,我揣著相機與錄音,去河邊找鬼禽篱。 笑死畜伐,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的躺率。 我是一名探鬼主播玛界,決...
    沈念sama閱讀 40,448評論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼肥照!你這毒婦竟也來了脚仔?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,352評論 0 276
  • 序言:老撾萬榮一對情侶失蹤舆绎,失蹤者是張志新(化名)和其女友劉穎鲤脏,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體吕朵,經(jīng)...
    沈念sama閱讀 45,834評論 1 317
  • 正文 獨居荒郊野嶺守林人離奇死亡猎醇,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,992評論 3 338
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了努溃。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片硫嘶。...
    茶點故事閱讀 40,133評論 1 351
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖梧税,靈堂內(nèi)的尸體忽然破棺而出沦疾,到底是詐尸還是另有隱情称近,我是刑警寧澤,帶...
    沈念sama閱讀 35,815評論 5 346
  • 正文 年R本政府宣布哮塞,位于F島的核電站刨秆,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏忆畅。R本人自食惡果不足惜衡未,卻給世界環(huán)境...
    茶點故事閱讀 41,477評論 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望家凯。 院中可真熱鬧缓醋,春花似錦、人聲如沸绊诲。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,022評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽掂之。三九已至葫督,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間板惑,已是汗流浹背橄镜。 一陣腳步聲響...
    開封第一講書人閱讀 33,147評論 1 272
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留冯乘,地道東北人洽胶。 一個月前我還...
    沈念sama閱讀 48,398評論 3 373
  • 正文 我出身青樓,卻偏偏與公主長得像裆馒,于是被迫代替她去往敵國和親姊氓。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 45,077評論 2 355

推薦閱讀更多精彩內(nèi)容