?
This document uses PHP Chinese website manual Release
設(shè)置環(huán)境變量以指示docker
應(yīng)該對(duì)特定的計(jì)算機(jī)運(yùn)行命令。
$ 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中運(yùn)行的命令。跑動(dòng)docker-machine env -u
將打印unset
可以逆轉(zhuǎn)這種效果的命令。
$ 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
(如果你不知道哪個(gè)殼您正在使用,有一個(gè)很好的可能性,它是bash
)。但是,這些并不是Docker Machine支持的唯一shell。Docker機(jī)器檢測(cè)您的環(huán)境中可用的shell并列出它們。碼頭工人支持bash
,cmd
,powershell
,和emacs
。
如果你用fish
而SHELL
環(huán)境變量正確設(shè)置為fish
被發(fā)現(xiàn)了,docker-machine env name
將以下列格式打印值:fish
預(yù)期:
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)在應(yīng)自動(dòng)檢測(cè)您的外殼。如果自動(dòng)檢測(cè)不起作用,您仍然可以使用--shell
標(biāo)志for 覆蓋它docker-machine env
。
對(duì)于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
提示:另請(qǐng)參閱如何在當(dāng)前shell中取消設(shè)置環(huán)境變量。
env命令支持一個(gè)--no-proxy
標(biāo)志,它將確保創(chuàng)建的機(jī)器的IP地址被添加到NO_PROXY
/ no_proxy
環(huán)境變量。
在docker-machine
與互聯(lián)網(wǎng)訪問需要HTTP代理的網(wǎng)絡(luò)環(huán)境中使用本地VM提供程序(例如virtualbox
或vmwarefusion
)時(shí),此功能很有用。
$ 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
標(biāo)志來訪問關(guān)于設(shè)置創(chuàng)建的守護(hù)進(jìn)程的文檔docker-machine create
。