Docker 是一個 open source 專案,誕生於 2013 年初,Docker 屬於 Linux 容器的一種封裝,提供了簡單且易用的容器接口,在 2016 推出 Docker for windows 版本,相信大家或多或少都聽過甚至已經有在使用,自己也接觸過 docker 一小段時間,但都屬於玩票性質未好好研究,或許在新筆電重新安裝的時候是一個好契機可以靜下心來深入研究,以下簡單介紹 Docker 在 Windows 上的安裝流程
Step 1 : 首先進入到 Docker 官網 下載 Docker Desktop for windows,我選擇下載 Stable 版本
Step 2 : 下載 Docker Windows Installer 安裝檔到 download 資料夾,接著點擊執行檔
Step 3 : 在安裝前會先詢問是否要建立快捷鍵在桌面及預設用 Linux container (設定安裝完可以再修改)
Step 4 : 按下OK後接著會進行目前穩定的 Docker 2.0.0.2 版安裝 ( 2019/1)
Step 5 : 安裝完後安裝程式會偵測電腦的 Hyper-V 和 Containers 功能是否有開啟,如果未開啟的話會提示將兩者設定 enable (murmur : 之前安裝時沒有這提示,實在太貼心拉!!)
Step 6 : 順利安裝完畢後,會跳出下列畫面並提示你登入你的 Docker 帳號資訊
Step 7 : 登入之後可以在螢幕右下角看到 Docker is running,代表 Docker for Windows 安裝成功,點擊 Docker 按右鍵可以看到 Docker 的資訊
Note 1 : 在 Step 3 中如果第二項預設已 Linux container 為主,在 Docker 按右鍵就可以看到選單中一項 switch to windows containers 可以針對 Windows / Linux 兩者進行切換動作
Note 2 : Step 5 步驟可以於安裝前先手動開啟設定 Container & Hyper-V,設定路徑為
控制台 > 開啟或關閉 Windows 功能 > Container & Hyper-V 兩者選項打勾 (若是啟動 Hyper-V有遇到問題可以參考 MSDN 在 Windows 10 上安裝 Hyper-V 文章)
在 Docker 中有提供相當多的 command line 指令供開發者操作,詳細的 command line 說明與語法都可以在 官方文件 查詢到,在安裝完成 Docker 之後,可以執行查看版本與跑 Hello world 試試看是否正常
- docker version : docker version : 顯示 Docker 版本資訊
- docker run hello-world : Run a command in a new container
- PS D:\> docker version
- Client: Docker Engine - Community
- Version: 18.09.1
- API version: 1.39
- Go version: go1.10.6
- Git commit: 4c52b90
- Built: Wed Jan 9 19:34:26 2019
- OS/Arch: windows/amd64
- Experimental: false
- Server: Docker Engine - Community
- Engine:
- Version: 18.09.1
- API version: 1.39 (minimum version 1.24)
- Go version: go1.10.6
- Git commit: 4c52b90
- Built: Wed Jan 9 19:50:10 2019
- OS/Arch: windows/amd64
- Experimental: false
程式說明 :
- PS D:\> Docker run hello-world
- Unable to find image 'hello-world:latest' locally
- latest: Pulling from library/hello-world
- 6a5e981230da: Pull complete
- dc4b656f6979: Pull complete
- 2848c5402b33: Pull complete
- 9e0171b11ac8: Pull complete
- Digest: sha256:2557e3c07ed1e38f26e389462d03ed943586f744621577a99efb77324b0fe535
- 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.
- (windows-amd64, nanoserver-1809)
- 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 a Windows Server container with:
- PS C:\> docker run -it mcr.microsoft.com/windows/servercore powershell
- 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/get-started/
- Line 2 : 發現 local 並沒有要執行的 hello-world image
- Line 3-9 : 到 libary 把 hello-world image pull 下來進行下載的動作
- Line 11 : 執行結果 hello from docker
以上詳細介紹了 Docker for Windows 的安裝流程,也在最後簡單說明下 command line 下 hello world 感受一下 docker,但其實這都只是的冰山一角還有更多好用功能與指令,例如說管理 container、如何建立自己的 image 印象檔、使用 docker-compose 進行部署等,更可以顯示出 Docker 的強大之處,雖來介紹文晚了別人好幾步(年),日後有時間希望可以慢慢補齊 XDDD
Docker
Docker Commandline
Docker 入门教程
0 意見:
張貼留言