?
本文檔使用 PHP中文網(wǎng)手冊 發(fā)布
創(chuàng)建一臺機器。需要該--driver
標志來指示應在哪個提供商(VirtualBox,DigitalOcean,AWS等)上創(chuàng)建機器,以及用于指示所創(chuàng)建機器的名稱的參數(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ū)動程序的標志。這些主要控制用戶可能希望定制的機器供應過程(包括創(chuàng)建Docker Swarm容器)的各個方面。
$ 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ū)動程序可以指定機器可以接受的標志作為其插件代碼的一部分。這些允許用戶自定義創(chuàng)建的機器的特定于提供者的參數(shù),例如size(--amazonec2-instance-type m1.medium
),地理區(qū)域(--amazonec2-region us-west-1
)等。
若要查看特定于提供程序的標志,只需傳遞--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
您可能會注意到一些標志也指定了它們與之關(guān)聯(lián)的環(huán)境變量(位于該行的最左側(cè))。如果這些環(huán)境變量在docker-machine create
被調(diào)用時被設置,Docker Machine將使用它們作為標志的默認值。
作為創(chuàng)建過程的一部分,DockerMachine安裝Docker并使用一些合理的默認設置對其進行配置。例如,它允許通過tcp與基于tls的加密進行連接,并且默認為存儲驅(qū)動程序如果有的話。
在幾種情況下,用戶可能想要為創(chuàng)建的Docker引擎(也稱為Docker 守護進程)自己設置選項。例如,他們可能希望允許使用守護進程的標志連接到他們正在運行的注冊表--insecure-registry
。Docker Machine支持通過create
開頭的命令標志為創(chuàng)建的引擎配置這些選項--engine
。
請注意,DockerMachine只是在守護進程上設置配置的參數(shù),而不為您設置任何“依賴項”。例如,如果您指定創(chuàng)建的守護進程應該使用btrfs
作為一個存儲驅(qū)動程序,您仍然必須確保安裝了適當?shù)囊蕾図棧呀?jīng)創(chuàng)建了BTRFS文件系統(tǒng),等等。
下面是一個示例用法:
$ 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)建一個在本地運行的虛擬機,該虛擬機使用overlay
存儲后端,具有鍵值對。foo=bar
和spam=eggs
作為引擎上的標簽,并允許從不安全的注冊表推舉/拉動位于registry.myco.com
.您可以通過檢查docker info
*
$ eval $(docker-machine env foobarmachine)$ docker info Containers: 0Images: 0Storage Driver: overlay...Name: foobarmachine...Labels: foo=bar spam=eggs provider=virtualbox
所支持的標志如下:
--engine-insecure-registry
*具體說明不安全注冊若要允許使用創(chuàng)建的引擎,請執(zhí)行以下操作
--engine-registry-mirror
*具體說明注冊表鏡像使用
--engine-label
*具體說明標簽對于創(chuàng)建的引擎
--engine-storage-driver
*具體說明存儲驅(qū)動程序與發(fā)動機一起使用
如果引擎支持多次指定標志(例如with --label
),那么Docker Machine也是如此。
--engine-opt
,可用于使用語法指定任意守護進程選項。--engine-opt flagname=value
.例如,若要指定守護進程應使用8.8.8.8
作為所有容器的dns服務器,并始終使用syslog
日志驅(qū)動器您可以運行以下CREATE命令:
$ docker-machine create -d virtualbox \ --engine-opt dns=8.8.8.8 \ --engine-opt log-driver=syslog \ gdns
另外,Docker Machine支持一個標志,--engine-env
,它可以使用語法指定要在引擎內(nèi)設置的任意環(huán)境變量。--engine-env name=value
例如,若要指定引擎應使用example.com
作為代理服務器,可以運行以下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引擎選項之外,您還可以使用Machine指定應該如何配置所創(chuàng)建的Swarm主機。有一個--swarm-strategy
標志,您可以使用它來指定Docker Swarm應該使用的調(diào)度策略(機器默認為spread
策略)。還有一個通用--swarm-opt
選項,它與上述--engine-opt
選項類似,只是它指定了用于swarm manage
命令(用于引導主節(jié)點)而不是基本命令的選項。您可以使用它來配置強大的用戶可能感興趣的功能,例如配置心跳間隔或Swarm過度提交資源的意愿。還有一個--swarm-experimental
標志,允許你訪問Docker Swarm中的實驗性功能。
如果您不確定如何配置這些選項,最好不要指定配置。DockerMachine會為您選擇合理的默認設置,您不必擔心。
示例創(chuàng)建:
$ docker-machine create -d virtualbox \ --swarm \ --swarm-master \ --swarm-discovery token://<token> \ --swarm-strategy binpack \ --swarm-opt heartbeat=5s \ upbeat
這將將群集調(diào)度策略設置為“binpack”%28pack,在每個主機中盡可能嚴格地將其分配到容器中,而不是將它們分散到%29,“心跳”間隔為5秒。
由于許多驅(qū)動程序需要一定的條件才能成功執(zhí)行創(chuàng)建(例如,應安裝VirtualBox或提供的API憑據(jù)應該有效),Docker Machine會指定一個“預創(chuàng)建檢查”在司機一級。
如果此預創(chuàng)建檢查成功,Docker Machine將按正常方式繼續(xù)創(chuàng)建.。如果預創(chuàng)建檢查失敗,DockerMachine進程將退出狀態(tài)代碼3,以指示非零退出的源是預創(chuàng)建檢查失敗。