?
This document uses PHP Chinese website manual Release
創(chuàng)建一臺(tái)機(jī)器。需要該--driver
標(biāo)志來(lái)指示應(yīng)在哪個(gè)提供商(VirtualBox,DigitalOcean,AWS等)上創(chuàng)建機(jī)器,以及用于指示所創(chuàng)建機(jī)器的名稱的參數(shù)。
$ docker-machine create --driver virtualbox dev Creating CA: /home/username/.docker/machine/certs/ca.pem Creating client certificate: /home/username/.docker/machine/certs/cert.pem Image cache does not exist, creating it at /home/username/.docker/machine/cache... No default boot2docker iso found locally, downloading the latest release... Downloading https://github.com/boot2docker/boot2docker/releases/download/v1.6.2/boot2docker. iso to /home/username/.docker/machine/cache/boot2docker.iso... Creating VirtualBox VM... Creating SSH key... Starting VirtualBox VM... Starting VM...To see how to connect Docker to this machine, run: docker-machine env dev
該docker-machine create
命令有一些適用于所有驅(qū)動(dòng)程序的標(biāo)志。這些主要控制用戶可能希望定制的機(jī)器供應(yīng)過(guò)程(包括創(chuàng)建Docker Swarm容器)的各個(gè)方面。
$ docker-machine create Docker Machine Version: 0.5.0 (45e3688)Usage: docker-machine create [OPTIONS] [arg...]Create a machine.Run 'docker-machine create --driver name' to include the create flags for that driver in the help text.Options: --driver, -d "none" Driver to create machine with. --engine-install-url "https://get.docker.com" Custom URL to use for engine installation [$MACHINE_DOCKER_INSTALL_URL] --engine-opt [--engine-opt option --engine-opt option] Specify arbitrary flags to include with the created engine in the form flag=value --engine-insecure-registry [--engine-insecure-registry option --engine-insecure-registry option] Specify insecure registries to allow with the created engine --engine-registry-mirror [--engine-registry-mirror option --engine-registry-mirror option] Specify registry mirrors to use [$ENGINE_REGISTRY_MIRROR] --engine-label [--engine-label option --engine-label option] Specify labels for the created engine --engine-storage-driver Specify a storage driver to use with the engine --engine-env [--engine-env option --engine-env option] Specify environment variables to set in the engine --swarm Configure Machine with Swarm --swarm-image "swarm:latest" Specify Docker image to use for Swarm [$MACHINE_SWARM_IMAGE] --swarm-master Configure Machine to be a Swarm master --swarm-discovery Discovery service to use with Swarm --swarm-strategy "spread" Define a default scheduling strategy for Swarm --swarm-opt [--swarm-opt option --swarm-opt option] Define arbitrary flags for swarm --swarm-host "tcp://0.0.0.0:3376" ip/socket to listen on for Swarm master --swarm-addr addr to advertise for Swarm (default: detect and use the machine IP) --swarm-experimental Enable Swarm experimental features
此外,驅(qū)動(dòng)程序可以指定機(jī)器可以接受的標(biāo)志作為其插件代碼的一部分。這些允許用戶自定義創(chuàng)建的機(jī)器的特定于提供者的參數(shù),例如size(--amazonec2-instance-type m1.medium
),地理區(qū)域(--amazonec2-region us-west-1
)等。
若要查看特定于提供程序的標(biāo)志,只需傳遞--driver
調(diào)用create
幫助短信。
$ docker-machine create --driver virtualbox --help Usage: docker-machine create [OPTIONS] [arg...] Create a machine.Run 'docker-machine create --driver name' to include the create flags for that driver in the help text.Options: --driver, -d "none" Driver to create machine with. --engine-env [--engine-env option --engine-env option] Specify environment variables to set in the engine --engine-insecure-registry [--engine-insecure-registry option --engine-insecure-registry option] Specify insecure registries to allow with the created engine --engine-install-url "https://get.docker.com" Custom URL to use for engine installation [$MACHINE_DOCKER_INSTALL_URL] --engine-label [--engine-label option --engine-label option] Specify labels for the created engine --engine-opt [--engine-opt option --engine-opt option] Specify arbitrary flags to include with the created engine in the form flag=value --engine-registry-mirror [--engine-registry-mirror option --engine-registry-mirror option] Specify registry mirrors to use [$ENGINE_REGISTRY_MIRROR] --engine-storage-driver Specify a storage driver to use with the engine --swarm Configure Machine with Swarm --swarm-addr addr to advertise for Swarm (default: detect and use the machine IP) --swarm-discovery Discovery service to use with Swarm --swarm-experimental Enable Swarm experimental features --swarm-host "tcp://0.0.0.0:3376" ip/socket to listen on for Swarm master --swarm-image "swarm:latest" Specify Docker image to use for Swarm [$MACHINE_SWARM_IMAGE] --swarm-master Configure Machine to be a Swarm master --swarm-opt [--swarm-opt option --swarm-opt option] Define arbitrary flags for swarm --swarm-strategy "spread" Define a default scheduling strategy for Swarm --virtualbox-boot2docker-url The URL of the boot2docker image. Defaults to the latest available version [$VIRTUALBOX_BOOT2DOCKER_URL] --virtualbox-cpu-count "1" number of CPUs for the machine (-1 to use the number of CPUs available) [$VIRTUALBOX_CPU_COUNT] --virtualbox-disk-size "20000" Size of disk for host in MB [$VIRTUALBOX_DISK_SIZE] --virtualbox-host-dns-resolver Use the host DNS resolver [$VIRTUALBOX_HOST_DNS_RESOLVER] --virtualbox-dns-proxy Proxy all DNS requests to the host [$VIRTUALBOX_DNS_PROXY] --virtualbox-hostonly-cidr "192.168.99.1/24" Specify the Host Only CIDR [$VIRTUALBOX_HOSTONLY_CIDR] --virtualbox-hostonly-nicpromisc "deny" Specify the Host Only Network Adapter Promiscuous Mode [$VIRTUALBOX_HOSTONLY_NIC_PROMISC] --virtualbox-hostonly-nictype "82540EM" Specify the Host Only Network Adapter Type [$VIRTUALBOX_HOSTONLY_NIC_TYPE] --virtualbox-import-boot2docker-vm The name of a Boot2Docker VM to import --virtualbox-memory "1024" Size of memory for host in MB [$VIRTUALBOX_MEMORY_SIZE] --virtualbox-no-share Disable the mount of your home directory
您可能會(huì)注意到一些標(biāo)志也指定了它們與之關(guān)聯(lián)的環(huán)境變量(位于該行的最左側(cè))。如果這些環(huán)境變量在docker-machine create
被調(diào)用時(shí)被設(shè)置,Docker Machine將使用它們作為標(biāo)志的默認(rèn)值。
作為創(chuàng)建過(guò)程的一部分,DockerMachine安裝Docker并使用一些合理的默認(rèn)設(shè)置對(duì)其進(jìn)行配置。例如,它允許通過(guò)tcp與基于tls的加密進(jìn)行連接,并且默認(rèn)為存儲(chǔ)驅(qū)動(dòng)程序如果有的話。
在幾種情況下,用戶可能想要為創(chuàng)建的Docker引擎(也稱為Docker 守護(hù)進(jìn)程)自己設(shè)置選項(xiàng)。例如,他們可能希望允許使用守護(hù)進(jìn)程的標(biāo)志連接到他們正在運(yùn)行的注冊(cè)表--insecure-registry
。Docker Machine支持通過(guò)create
開頭的命令標(biāo)志為創(chuàng)建的引擎配置這些選項(xiàng)--engine
。
請(qǐng)注意,DockerMachine只是在守護(hù)進(jìn)程上設(shè)置配置的參數(shù),而不為您設(shè)置任何“依賴項(xiàng)”。例如,如果您指定創(chuàng)建的守護(hù)進(jìn)程應(yīng)該使用btrfs
作為一個(gè)存儲(chǔ)驅(qū)動(dòng)程序,您仍然必須確保安裝了適當(dāng)?shù)囊蕾図?xiàng),已經(jīng)創(chuàng)建了BTRFS文件系統(tǒng),等等。
下面是一個(gè)示例用法:
$ docker-machine create -d virtualbox \ --engine-label foo=bar \ --engine-label spam=eggs \ --engine-storage-driver overlay \ --engine-insecure-registry registry.myco.com \ foobarmachine
這將在VirtualBox中創(chuàng)建一個(gè)在本地運(yùn)行的虛擬機(jī),該虛擬機(jī)使用overlay
存儲(chǔ)后端,具有鍵值對(duì)。foo=bar
和spam=eggs
作為引擎上的標(biāo)簽,并允許從不安全的注冊(cè)表推舉/拉動(dòng)位于registry.myco.com
.您可以通過(guò)檢查docker info
*
$ eval $(docker-machine env foobarmachine)$ docker info Containers: 0Images: 0Storage Driver: overlay...Name: foobarmachine...Labels: foo=bar spam=eggs provider=virtualbox
所支持的標(biāo)志如下:
--engine-insecure-registry
*具體說(shuō)明不安全注冊(cè)若要允許使用創(chuàng)建的引擎,請(qǐng)執(zhí)行以下操作
--engine-registry-mirror
*具體說(shuō)明注冊(cè)表鏡像使用
--engine-label
*具體說(shuō)明標(biāo)簽對(duì)于創(chuàng)建的引擎
--engine-storage-driver
*具體說(shuō)明存儲(chǔ)驅(qū)動(dòng)程序與發(fā)動(dòng)機(jī)一起使用
如果引擎支持多次指定標(biāo)志(例如with --label
),那么Docker Machine也是如此。
--engine-opt
,可用于使用語(yǔ)法指定任意守護(hù)進(jìn)程選項(xiàng)。--engine-opt flagname=value
.例如,若要指定守護(hù)進(jìn)程應(yīng)使用8.8.8.8
作為所有容器的dns服務(wù)器,并始終使用syslog
日志驅(qū)動(dòng)器您可以運(yùn)行以下CREATE命令:
$ docker-machine create -d virtualbox \ --engine-opt dns=8.8.8.8 \ --engine-opt log-driver=syslog \ gdns
另外,Docker Machine支持一個(gè)標(biāo)志,--engine-env
,它可以使用語(yǔ)法指定要在引擎內(nèi)設(shè)置的任意環(huán)境變量。--engine-env name=value
例如,若要指定引擎應(yīng)使用example.com
作為代理服務(wù)器,可以運(yùn)行以下CREATE命令:
$ docker-machine create -d virtualbox \ --engine-env HTTP_PROXY=http://example.com:8080 \ --engine-env HTTPS_PROXY=https://example.com:8080 \ --engine-env NO_PROXY=example2.com \ proxbox
除了能夠配置上面列出的Docker引擎選項(xiàng)之外,您還可以使用Machine指定應(yīng)該如何配置所創(chuàng)建的Swarm主機(jī)。有一個(gè)--swarm-strategy
標(biāo)志,您可以使用它來(lái)指定Docker Swarm應(yīng)該使用的調(diào)度策略(機(jī)器默認(rèn)為spread
策略)。還有一個(gè)通用--swarm-opt
選項(xiàng),它與上述--engine-opt
選項(xiàng)類似,只是它指定了用于swarm manage
命令(用于引導(dǎo)主節(jié)點(diǎn))而不是基本命令的選項(xiàng)。您可以使用它來(lái)配置強(qiáng)大的用戶可能感興趣的功能,例如配置心跳間隔或Swarm過(guò)度提交資源的意愿。還有一個(gè)--swarm-experimental
標(biāo)志,允許你訪問(wèn)Docker Swarm中的實(shí)驗(yàn)性功能。
如果您不確定如何配置這些選項(xiàng),最好不要指定配置。DockerMachine會(huì)為您選擇合理的默認(rèn)設(shè)置,您不必?fù)?dān)心。
示例創(chuàng)建:
$ docker-machine create -d virtualbox \ --swarm \ --swarm-master \ --swarm-discovery token://<token> \ --swarm-strategy binpack \ --swarm-opt heartbeat=5s \ upbeat
這將將群集調(diào)度策略設(shè)置為“binpack”%28pack,在每個(gè)主機(jī)中盡可能嚴(yán)格地將其分配到容器中,而不是將它們分散到%29,“心跳”間隔為5秒。
由于許多驅(qū)動(dòng)程序需要一定的條件才能成功執(zhí)行創(chuàng)建(例如,應(yīng)安裝VirtualBox或提供的API憑據(jù)應(yīng)該有效),Docker Machine會(huì)指定一個(gè)“預(yù)創(chuàng)建檢查”在司機(jī)一級(jí)。
如果此預(yù)創(chuàng)建檢查成功,Docker Machine將按正常方式繼續(xù)創(chuàng)建.。如果預(yù)創(chuàng)建檢查失敗,DockerMachine進(jìn)程將退出狀態(tài)代碼3,以指示非零退出的源是預(yù)創(chuàng)建檢查失敗。