網頁

2020/5/1

Docker Machine 建立machine create docker machine

使用Docker Machine建立新的machine的方法如下。

範立環境:

  • Windows 7 64Bit
  • Docker Machine version 0.16.1, build cce350d7
  • Oracle VirtualBox 版本 5.2.20 r125813 (Qt5.6.2)

注意:本範例的Docker Machine及VirtualBox是由Docker Toolbox安裝


使用docker-machine create --driver=<driver-name> <machine-name>建立新machine。
<driver-name>為Macchine使用的driver名稱。<machine-name>為建立的machine名稱。

例如輸入docker-machine create --driver=virtualbox demo-docker以Oracle VirtualBox driver建立一個名稱為demo-docker的machine。

注意:如果VirtualBox內有預設的default machine正在運行,則建立新的machine時會卡在Waiting for an IP階段,所以先用docker-machine stop default把default machine停止再建立新的machine。


C:\>docker-machine create --driver=virtualbox demo-docker
Running pre-create checks...
Creating machine...
(demo-docker) Copying C:\Users\matt\.docker\machine\cache\boot2docker.iso to C:\Users\matt\.docker\machine\machines\demo-docker\boot2docker.iso...
(demo-docker) Creating VirtualBox VM...
(demo-docker) Creating SSH key...
(demo-docker) Starting the VM...
(demo-docker) Check network to re-create if needed...
(demo-docker) Windows might ask for the permission to configure a dhcp server. Sometimes, such confirmation window is minimized in the taskbar.
(demo-docker) 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 demo-docker

建立好後使用docker-machine ls列出現有的machine。第二個demo-docker即為新建的machine。

C:\>docker-machine ls
NAME          ACTIVE   DRIVER       STATE     URL                         SWARM  DOCKER     ERRORS
default       -        virtualbox   Stopped                                      Unknown
demo-docker   -        virtualbox   Running   tcp://192.168.99.101:2376          v19.03.5

Docker Machine default與demo-docker在系統運作示意圖。

+-------------------+ +--------------------+
| Docker container  | |  Docker container  |
+-------------------+ +--------------------+
|  Docker Engine    | |   Docker Engine    |
+-------------------+ +--------------------+
|  Docker Machine   | |   Docker Machine   |
|    (default)      | |   (demo-docker)    |
+-------------------+-+--------------------+
|           VM OS (ViratualBox)            |
+------------------------------------------+
|           HOST OS (Windows7)             |
+------------------------------------------+
|       Infrastructure (Hardware)          |
+------------------------------------------+

沒有留言:

張貼留言