?
本文檔使用 PHP中文網手冊 發(fā)布
設置環(huán)境變量以指示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.
上述輸出旨在供彈bash
和zsh
(如果你不知道哪個殼您正在使用,有一個很好的可能性,它是bash
)。但是,這些并不是Docker Machine支持的唯一shell。Docker機器檢測您的環(huán)境中可用的shell并列出它們。碼頭工人支持bash
,cmd
,powershell
,和emacs
。
如果你用fish
而SHELL
環(huán)境變量正確設置為fish
被發(fā)現(xiàn)了,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.exe
,docker-machine env
Docker Machine現(xiàn)在應自動檢測您的外殼。如果自動檢測不起作用,您仍然可以使用--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中取消設置環(huán)境變量。
env命令支持一個--no-proxy
標志,它將確保創(chuàng)建的機器的IP地址被添加到NO_PROXY
/ no_proxy
環(huán)境變量。
在docker-machine
與互聯(lián)網訪問需要HTTP代理的網絡環(huán)境中使用本地VM提供程序(例如virtualbox
或vmwarefusion
)時,此功能很有用。
$ 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
標志來訪問關于設置創(chuàng)建的守護進程的文檔docker-machine create
。