Docker 17
机器 | Machine

docker机器创建 | docker-machine create

码头-机器创建

创建一台机器。需要该--driver标志来指示应在哪个提供商(VirtualBox,DigitalOcean,AWS等)上创建机器,以及用于指示所创建机器的名称的参数。

$ 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命令有一些适用于所有驱动程序的标志。这些主要控制用户可能希望定制的机器供应过程(包括创建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

此外,驱动程序可以指定机器可以接受的标志作为其插件代码的一部分。这些允许用户自定义创建的机器的特定于提供者的参数,例如size(--amazonec2-instance-type m1.medium),地理区域(--amazonec2-region us-west-1)等。

若要查看特定于提供程序的标志,只需传递--driver调用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

您可能会注意到一些标志也指定了它们与之关联的环境变量(位于该行的最左侧)。如果这些环境变量在docker-machine create被调用时被设置,Docker Machine将使用它们作为标志的默认值。

为创建的Docker引擎指定配置选项

作为创建过程的一部分,DockerMachine安装Docker并使用一些合理的默认设置对其进行配置。例如,它允许通过tcp与基于tls的加密进行连接,并且默认为存储驱动程序如果有的话。

在几种情况下,用户可能想要为创建的Docker引擎(也称为Docker 守护进程)自己设置选项。例如,他们可能希望允许使用守护进程的标志连接到他们正在运行的注册表--insecure-registry。Docker Machine支持通过create开头的命令标志为创建的引擎配置这些选项--engine

请注意,DockerMachine只是在守护进程上设置配置的参数,而不为您设置任何“依赖项”。例如,如果您指定创建的守护进程应该使用btrfs作为一个存储驱动程序,您仍然必须确保安装了适当的依赖项,已经创建了BTRFS文件系统,等等。

下面是一个示例用法:

$ 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中创建一个在本地运行的虚拟机,该虚拟机使用overlay存储后端,具有键值对。foo=barspam=eggs作为引擎上的标签,并允许从不安全的注册表推举/拉动位于registry.myco.com.您可以通过检查docker info*

$ eval $(docker-machine env foobarmachine) $ docker info Containers: 0 Images: 0 Storage Driver: overlay ... Name: foobarmachine ... Labels: foo=bar spam=eggs provider=virtualbox

所支持的标志如下:

  • --engine-insecure-registry*具体说明不安全注册若要允许使用创建的引擎,请执行以下操作

  • --engine-registry-mirror*具体说明注册表镜像使用

  • --engine-label*具体说明标签对于创建的引擎

  • --engine-storage-driver*具体说明存储驱动程序与发动机一起使用

如果引擎支持多次指定标志(例如with --label),那么Doc​​ker Machine也是如此。

--engine-opt,可用于使用语法指定任意守护进程选项。--engine-opt flagname=value.例如,若要指定守护进程应使用8.8.8.8作为所有容器的dns服务器,并始终使用syslog日志驱动器您可以运行以下CREATE命令:

$ docker-machine create -d virtualbox \ --engine-opt dns=8.8.8.8 \ --engine-opt log-driver=syslog \ gdns

另外,Docker Machine支持一个标志,--engine-env,它可以使用语法指定要在引擎内设置的任意环境变量。--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群集选项

除了能够配置上面列出的Docker引擎选项之外,您还可以使用Machine指定应该如何配置所创建的Swarm主机。有一个--swarm-strategy标志,您可以使用它来指定Docker Swarm应该使用的调度策略(机器默认为spread策略)。还有一个通用--swarm-opt选项,它与上述--engine-opt选项类似,只是它指定了用于swarm manage命令(用于引导主节点)而不是基本命令的选项。您可以使用它来配置强大的用户可能感兴趣的功能,例如配置心跳间隔或Swarm过度提交资源的意愿。还有一个--swarm-experimental标志,允许你访问Docker Swarm中的实验性功能。

如果您不确定如何配置这些选项,最好不要指定配置。DockerMachine会为您选择合理的默认设置,您不必担心。

示例创建:

$ docker-machine create -d virtualbox \ --swarm \ --swarm-master \ --swarm-discovery token://<token> \ --swarm-strategy binpack \ --swarm-opt heartbeat=5s \ upbeat

这将将群集调度策略设置为“binpack”%28pack,在每个主机中尽可能严格地将其分配到容器中,而不是将它们分散到%29,“心跳”间隔为5秒。

预创建检查

由于许多驱动程序需要一定的条件才能成功执行创建(例如,应安装VirtualBox或提供的API凭据应该有效),Docker Machine会指定一个“预创建检查”在司机一级。

如果此预创建检查成功,Docker Machine将按正常方式继续创建.。如果预创建检查失败,DockerMachine进程将退出状态代码3,以指示非零退出的源是预创建检查失败。

机器创建子命令