文字
分享

设置环境变量以指示docker应该对特定的计算机运行命令。

$ docker-machine env --help

Usage: docker-machine env [OPTIONS] [arg...]Display the commands to set up the environment for the Docker client

Description:
   Argument is a machine name.Options:   
   --swarm	Display the Swarm config instead of the Docker daemon   
   --shell 	Force environment to be configured for a specified shell: [fish, cmd, powershell, tcsh], default is sh/bash   
   --unset, -u	Unset variables instead of setting them   
   --no-proxy	Add machine IP to NO_PROXY environment variable

docker-machine env machinename打印出来export可以在子shell中运行的命令。跑动docker-machine env -u将打印unset可以逆转这种效果的命令。

$ env | grep DOCKER
$ eval "$(docker-machine env dev)"$ env | grep DOCKER
DOCKER_HOST=tcp://192.168.99.101:2376DOCKER_CERT_PATH=/Users/nathanleclaire/.docker/machines/.client
DOCKER_TLS_VERIFY=1DOCKER_MACHINE_NAME=dev
$ # If you run a docker command, now it will run against that host.$ eval "$(docker-machine env -u)"$ env | grep DOCKER
$ # The environment variables have been unset.

上述输出旨在供弹bashzsh(如果你不知道哪个壳您正在使用,有一个很好的可能性,它是bash)。但是,这些并不是Docker Machine支持的唯一shell。Docker机器检测您的环境中可用的shell并列出它们。码头工人支持bashcmdpowershell,和emacs

如果你用fishSHELL环境变量正确设置为fish被发现了,docker-machine env name将以下列格式打印值:fish预期:

set -x DOCKER_TLS_VERIFY 1;
set -x DOCKER_CERT_PATH "/Users/nathanleclaire/.docker/machine/machines/overlay";
set -x DOCKER_HOST tcp://192.168.99.102:2376;set -x DOCKER_MACHINE_NAME overlay
# Run this command to configure your shell:# eval "$(docker-machine env overlay)"

如果您在Windows上并使用PowerShell cmd.exedocker-machine envDocker Machine现在应自动检测您的外壳。如果自动检测不起作用,您仍然可以使用--shell标志for 覆盖它docker-machine env

对于PowerShell:

$ docker-machine.exe env --shell powershell dev
$Env:DOCKER_TLS_VERIFY = "1"$Env:DOCKER_HOST = "tcp://192.168.99.101:2376"$Env:DOCKER_CERT_PATH = "C:\Users\captain\.docker\machine\machines\dev"$Env:DOCKER_MACHINE_NAME = "dev"# Run this command to configure your shell:# docker-machine.exe env --shell=powershell dev | Invoke-Expression

cmd.exe*

$ docker-machine.exe env --shell cmd devset DOCKER_TLS_VERIFY=1set DOCKER_HOST=tcp://192.168.99.101:2376set DOCKER_CERT_PATH=C:\Users\captain\.docker\machine\machines\devset DOCKER_MACHINE_NAME=dev
# Run this command to configure your shell: copy and paste the above values into your command prompt

提示:另请参阅如何在当前shell中取消设置环境变量。

将创建的机器排除在代理之外

env命令支持一个--no-proxy标志,它将确保创建的机器的IP地址被添加到NO_PROXY/ no_proxy环境变量。

docker-machine与互联网访问需要HTTP代理的网络环境中使用本地VM提供程序(例如virtualboxvmwarefusion)时,此功能很有用。

$ docker-machine env --no-proxy defaultexport DOCKER_TLS_VERIFY="1"export DOCKER_HOST="tcp://192.168.99.104:2376"export DOCKER_CERT_PATH="/Users/databus23/.docker/machine/certs"export DOCKER_MACHINE_NAME="default"export NO_PROXY="192.168.99.104"# Run this command to configure your shell:# eval "$(docker-machine env default)"

您可能还想HTTP_PROXY使用--engine-env标志来访问关于设置创建的守护进程的文档docker-machine create