Titangene (Titan)
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Versions and GitHub Sync Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
Invitee
Publish Note

Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

Your note will be visible on your profile and discoverable by anyone.
Your note is now live.
This note is visible on your profile and discoverable online.
Everyone on the web can find and read all notes of this public team.
See published notes
Unpublish note
Please check the box to agree to the Community Guidelines.
View profile
Engagement control
Commenting
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
  • Everyone
Suggest edit
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
Emoji Reply
Enable
Import from Dropbox Google Drive Gist Clipboard
   owned this note    owned this note      
Published Linked with GitHub
2
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
<span style="font-size:60px">Docker Machine 入門</span> === ![](https://i.imgur.com/5JFz36P.png =120x) #### 郭柏均 (Titangene) - E-mail: [titangene.tw@gmail.com](mailto:titangene.tw@gmail.com) - GitHub: [Titangene](https://github.com/titangene) - Blog: titangene.github.io --- :::warning 提醒: 本篇是在 Windows 10 家用版的 cmd shell 下操作 ::: <!-- SET MACHINE_STORAGE_PATH=D:\docker\machine docker-machine start default --> --- ## Docker Engine ## & ## Docker Machine --- <!-- - Docker 是一種容器化技術,可以把你的應用程式連同環境一起打包,部署的時候不用擔心環境的問題 - 可以簡化重建環境的過程、降低維運成本,並且讓開發、測試和正式環境無縫接軌 Docker Engine 接受來自 CLI 的 `docker` 指令 --> 平常我們講的 "Docker" 指的是 Docker Engine, 是由下面所組成的 client-server application: - Docker daemon - 與 daemon 互動的介面:REST API - 與 daemon 通訊的 CLI client ![](https://i.imgur.com/ZVQeC0w.png =200x)<span style="font-size:16px">[Ref](https://docs.docker.com/machine/overview/)</span> --- ![](https://i.imgur.com/5kTHXzC.png =700x)<span style="font-size:16px">[Ref](https://docs.docker.com/machine/overview/)</span> --- Docker Machine 是用來設定和管理 Dockerized 主機 (帶有 Docker Engine 的主機) 的工具,通常會在你的 local 主機安裝。裡面包含的指令: - command line client:`docker-machine` - Docker Engine client:`docker` 可以使用 Docker Machine 在你本地的 Mac 或 Windows、公司網路、資料中心或雲端供應商 (例如:Azure、AWS … 等) 上快速建置 Docker 主機 而那些 Dockerized 主機可被稱為 "machines" <!-- 簡單來說,Docker Machine 就是可以快速把 Docker 環境建立起來的工具。如果沒有 Docker Machine 的話,就要先在自己的主機上安裝 Docker 環境,如果有很多台的時候就需要做重複的動作。有了 Docker Machine 就可以快速的把 VM 和 Docker 環境建立起來,而且也可以在本地的主機或雲端平台上架設 Docker Machine。 使用 `docker-machine` 指令,你可以啟動、檢查、停止和重啟託管的主機、升級 Docker client 和 daemon,並設定 Docker client 與你的主機連接。 --> --- ## 安裝 Docker Machine 至官方的 [Github Release](https://github.com/docker/machine/releases/) 頁面下載 詳情請參考官方的文件:[Install Docker Machine](https://docs.docker.com/machine/install-machine/) --- ### `docker-machine -v` 查看目前 Docker Machine 的版本 ```shell $ docker-machine -v docker-machine version 0.13.0, build 9ba6da9 ``` --- ### 本地端未安裝 Docker Daemon 且未連線至遠端 server 時會出現的錯誤訊息 像我沒有在本地端上安裝 Docker Daemon (因為 Host 的 OS 是 Windows 家用版,不能安裝 [Docker for Windows](https://docs.docker.com/docker-for-windows/install/),只能安裝 [Docker Toolbox](https://hackmd.io/c/H1WITKNUz/%2FHyBPRDfDf)) ,所以不管執行任何 `docker` 指令都會出現下面錯誤: ```shell $ docker ps error during connect: Get http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.36/containers/json: open //./pipe/docker_engine: The system cannot find the file specified. In the default daemon configuration on Windows, the docker client must be run elevated to connect. This error may also indicate that the docker daemon is not running. ``` <!-- 其實錯誤訊息寫得很清楚了,在 Host 上的 Docker client 必須要連接到 Docker daemon 才能操作 Docker,Docker daemon 可能是遠端、雲端或是你本機的 VM,如果你沒有連接或是 Docker daemon 沒有執行都會無法在 Host 上的 Docker client 直接操作 Docker。 --> --- 執行 `docker version` 指令 不會顯示 Server 的部分: ```shell $ docker version Client: Version: 18.02.0-ce API version: 1.36 Go version: go1.9.4 Git commit: fc4de447b5 Built: Mon Feb 12 19:03:38 2018 OS/Arch: windows/amd64 Experimental: false Orchestrator: swarm error during connect: Get http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.36/version: open //./pipe/docker_engine: The system cannot find the file specified. In the default daemon configuration on Windows, the docker client must be run elevated to connect. This error may also indicate that the docker daemon is not running. ``` --- ## Docker Machine 指令 --- ### `docker-machine create` 建立新的 Docker Machine - `-d`,`--driver`:設定建立 Docker Machine 的 driver,Docker 官方支援多種 driver,包括 AWS、Azure、GCE ... 等,詳情請參考官方的 [Machine drivers | Docker Documentation](https://docs.docker.com/) 文件 --- 以 VirtualBox 為例: ```shell $ docker-machine create -d [driver] [machine-name] ``` ```shell $ docker-machine create -d virtualbox dev Running pre-create checks... Creating machine... (dev) Copying C:\Users\Titan\.docker\machine\cache\boot2docker.iso to C:\Users\Titan\.docker\machine\machines\dev\boot2docker.iso... (dev) Creating VirtualBox VM... (dev) Creating SSH key... (dev) Starting the VM... (dev) Check network to re-create if needed... (dev) Windows might ask for the permission to configure a dhcp server. Sometimes, such confirmation window is minimized in the taskbar. (dev) Waiting for an IP... Waiting for machine to be running, this may take a few minutes... Detecting operating system of created instance... Waiting for SSH to be available... Detecting the provisioner... Provisioning with boot2docker... Copying certs to the local machine directory... Copying certs to the remote machine... Setting Docker configuration on the remote daemon... Checking connection to Docker... Docker is up and running! To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: docker-machine env dev ``` --- ### `docker-machine ls` 查看所有 Docker Machine 相關資訊 ```shell $ docker-machine ls NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS default * virtualbox Running tcp://192.168.99.100:2376 v18.02.0-ce dev - virtualbox Running tcp://192.168.99.101:2376 v18.02.0-ce ``` --- 列出訊息的欄位介紹: - `ACTIVE`:顯示 `*` 表示正在操作的 Docker Engine (使用 `docker-machine env` 指令最後的提示設定,將本地的 Docker Client 連接到在 VM 上執行的 Docker Engine),而顯示 `-` 則反之。 - `STATE`:Docker Engine 狀態 - `URL`:Docker Engine 所在 IP - `SWARM`:是否為 SWARM master or node - `DOCKER`:建立 Docker 時所安裝的 Docker 版本 --- ### `docker-machine env` ```shell $ docker-machine env [machine-name] ``` 可以將該 Docker Machine 連線時所需的環境變數列出來,方便切換環境。 該指令輸出的最後有個小提示,在不同的 shell 會有不同的指令,使用那段指令可以快速地把環境變數設定在目前的環境上,也就是可以將本地的 Docker Client 連接到在 VM 上執行的 Docker Engine。 --- 使用 `cmd` 的輸出結果: ```shell $ docker-machine env default SET DOCKER_TLS_VERIFY=1 SET DOCKER_HOST=tcp://192.168.99.100:2376 SET DOCKER_CERT_PATH=C:\Users\Titan\.docker\machine\machines\default SET DOCKER_MACHINE_NAME=default SET COMPOSE_CONVERT_WINDOWS_PATHS=true REM Run this command to configure your shell: REM @FOR /f "tokens=*" %i IN ('docker-machine env default') DO @%i ``` --- 使用 `bash` 的輸出結果: ```shell $ docker-machine env default export DOCKER_TLS_VERIFY="1" export DOCKER_HOST="tcp://192.168.99.100:2376" export DOCKER_CERT_PATH="C:\Users\Titan\.docker\machine\machines\default" export DOCKER_MACHINE_NAME="default" export COMPOSE_CONVERT_WINDOWS_PATHS="true" # Run this command to configure your shell: # eval $("D:\Program Files\Docker Toolbox\docker-machine.exe" env default) ``` --- ## 連結遠端 Docker daemon 執行 `docker-machine env` 指令輸出的最後小提示,就可以將本地的 Docker Client 連接到在 VM 上執行的 Docker Engine <!-- 下面指令只適用於 `cmd` shell,如果是其他 shell,可參考自己執行 `docker-machine env` 指令輸出的最後小提示,或是參考上一段落提供的輸出範例 --> ```shell $ @FOR /f "tokens=*" %i IN ('docker-machine env default') DO @%i ``` --- 接著就可以看到 `docker-machine ls` 指令中的 `ACTIVE` 欄位已從 `-` 變成 `*`,那就代表已成功連接 ```shell $ docker-machine ls NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS default * virtualbox Running tcp://192.168.99.100:2376 v18.02.0-ce ``` --- 使用 `docker version` 指令也可以看到 Docker server 的版本資訊: ```shell $ docker version Client: Version: 18.02.0-ce API version: 1.36 Go version: go1.9.4 Git commit: fc4de447b5 Built: Mon Feb 12 19:03:38 2018 OS/Arch: windows/amd64 Experimental: false Orchestrator: swarm Server: Engine: Version: 18.02.0-ce API version: 1.36 (minimum version 1.12) Go version: go1.9.3 Git commit: fc4de44 Built: Wed Feb 7 21:20:09 2018 OS/Arch: linux/amd64 Experimental: false ``` --- ### `docker-machine ssh` 連線到指定的 Docker Machine ```shell $ docker-machine ssh [machine-name] ``` ![](https://i.imgur.com/8qqywAd.png) --- ### `docker-machine ip` 查詢指定 Docker Machine 的 IP ```shell $ docker-machine ip [machine-name] ``` ```shell $ docker-machine ip default 192.168.99.100 ``` --- ### `docker-machine start` 執行 Docker Machine ```shell $ docker-machine start [machine-name] ``` ```shell $ docker-machine start default Starting "default"... (default) Check network to re-create if needed... (default) Windows might ask for the permission to configure a dhcp server. Sometimes, such confirmation window is minimized in the taskbar. (default) Waiting for an IP... Machine "default" was started. Waiting for SSH to be available... Detecting the provisioner... Started machines may have new IP addresses. You may need to re-run the `docker-machine env` command. $ docker-machine ls NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS default - virtualbox Running tcp://192.168.99.100:2376 v18.02.0-ce ``` --- ### `docker-machine restart` 重新啟動 Docker Machine ```shell $ docker-machine restart [machine-name] ``` ```shell $ docker-machine restart default Restarting "default"... (default) Check network to re-create if needed... (default) Windows might ask for the permission to configure a dhcp server. Sometimes, such confirmation window is minimized in the taskbar. (default) Waiting for an IP... Waiting for SSH to be available... Detecting the provisioner... Restarted machines may have new IP addresses. You may need to re-run the `docker-machine env` command. ``` --- ### `docker-machine rm` 刪除 Docker Machine ```shell $ docker-machine rm [machine-name] ``` ```shell $ docker-machine rm dev About to remove dev WARNING: This action will delete both local reference and remote instance. Are you sure? (y/n): y Successfully removed dev ``` --- ## 參考來源 - [Docker Machine | Docker Documentation](https://docs.docker.com/machine/)

Import from clipboard

Paste your markdown or webpage here...

Advanced permission required

Your current role can only read. Ask the system administrator to acquire write and comment permission.

This team is disabled

Sorry, this team is disabled. You can't edit this note.

This note is locked

Sorry, only owner can edit this note.

Reach the limit

Sorry, you've reached the max length this note can be.
Please reduce the content or divide it to more notes, thank you!

Import from Gist

Import from Snippet

or

Export to Snippet

Are you sure?

Do you really want to delete this note?
All users will lose their connection.

Create a note from template

Create a note from template

Oops...
This template has been removed or transferred.
Upgrade
All
  • All
  • Team
No template.

Create a template

Upgrade

Delete template

Do you really want to delete this template?
Turn this template into a regular note and keep its content, versions, and comments.

This page need refresh

You have an incompatible client version.
Refresh to update.
New version available!
See releases notes here
Refresh to enjoy new features.
Your user state has changed.
Refresh to load new user state.

Sign in

Forgot password

or

By clicking below, you agree to our terms of service.

Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
Wallet ( )
Connect another wallet

New to HackMD? Sign up

Help

  • English
  • 中文
  • Français
  • Deutsch
  • 日本語
  • Español
  • Català
  • Ελληνικά
  • Português
  • italiano
  • Türkçe
  • Русский
  • Nederlands
  • hrvatski jezik
  • język polski
  • Українська
  • हिन्दी
  • svenska
  • Esperanto
  • dansk

Documents

Help & Tutorial

How to use Book mode

Slide Example

API Docs

Edit in VSCode

Install browser extension

Contacts

Feedback

Discord

Send us email

Resources

Releases

Pricing

Blog

Policy

Terms

Privacy

Cheatsheet

Syntax Example Reference
# Header Header 基本排版
- Unordered List
  • Unordered List
1. Ordered List
  1. Ordered List
- [ ] Todo List
  • Todo List
> Blockquote
Blockquote
**Bold font** Bold font
*Italics font* Italics font
~~Strikethrough~~ Strikethrough
19^th^ 19th
H~2~O H2O
++Inserted text++ Inserted text
==Marked text== Marked text
[link text](https:// "title") Link
![image alt](https:// "title") Image
`Code` Code 在筆記中貼入程式碼
```javascript
var i = 0;
```
var i = 0;
:smile: :smile: Emoji list
{%youtube youtube_id %} Externals
$L^aT_eX$ LaTeX
:::info
This is a alert area.
:::

This is a alert area.

Versions and GitHub Sync
Get Full History Access

  • Edit version name
  • Delete

revision author avatar     named on  

More Less

Note content is identical to the latest version.
Compare
    Choose a version
    No search result
    Version not found
Sign in to link this note to GitHub
Learn more
This note is not linked with GitHub
 

Feedback

Submission failed, please try again

Thanks for your support.

On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

Please give us some advice and help us improve HackMD.

 

Thanks for your feedback

Remove version name

Do you want to remove this version name and description?

Transfer ownership

Transfer to
    Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

      Link with GitHub

      Please authorize HackMD on GitHub
      • Please sign in to GitHub and install the HackMD app on your GitHub repo.
      • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
      Learn more  Sign in to GitHub

      Push the note to GitHub Push to GitHub Pull a file from GitHub

        Authorize again
       

      Choose which file to push to

      Select repo
      Refresh Authorize more repos
      Select branch
      Select file
      Select branch
      Choose version(s) to push
      • Save a new version and push
      • Choose from existing versions
      Include title and tags
      Available push count

      Pull from GitHub

       
      File from GitHub
      File from HackMD

      GitHub Link Settings

      File linked

      Linked by
      File path
      Last synced branch
      Available push count

      Danger Zone

      Unlink
      You will no longer receive notification when GitHub file changes after unlink.

      Syncing

      Push failed

      Push successfully