Docker-Machine使用簡介

Why should I use Docker-machine

I have an older desktop system and want to run Docker on Mac or Windows

Installing Docker Machine on a Mac or Windows box with the Docker Toolbox installer provisions a local virtual machine with Docker Engine, gives you the ability to connect it, and run docker commands.

i

I want to provision Docker hosts on remote systems

If you have a Linux box as your primary system, and want to run docker commands, all you need to do is download and install Docker Engine. However, if you want an efficient way to provision multiple Docker hosts on a network, in the cloud or even locally, you need Docker Machine.

image

Installing Docker-Machine

  • Install Docker

  • Download the Docker-machine binary and extract it to your PATH.

MacOS:

<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="bash" contenteditable="false" cid="n49" mdtype="fences" style="font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-indent: 0px; text-transform: none; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); border: 1px solid rgb(231, 234, 237); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; padding: 8px 1em 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; caret-color: rgb(51, 51, 51); color: rgb(51, 51, 51); position: relative !important;">base=https://github.com/docker/machine/releases/tag/v0.16.0 &&
curl-Lbase/docker-machine-(uname -s)-$(uname -m)>/usr/local/bin/docker-machine &&
chmod+x /usr/local/bin/docker-machine</pre>

  • Install bash completion scripts

  • <pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="bash" contenteditable="false" cid="n60" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); border: 1px solid rgb(231, 234, 237); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; padding: 8px 1em 6px 0px; margin-bottom: 15px; margin-top: 0px; width: inherit; position: relative !important;">base=https://raw.githubusercontent.com/docker/machine/v0.16.0
    fori indocker-machine-prompt.bash docker-machine-wrapper.bash docker-machine.bash
    do
    sudowget"base/contrib/completion/bash/{i}"-P/etc/bash_completion.d
    doneTo enable the docker-machineshell prompt, add $(__docker_machine_ps1)to your PS1setting in~/.bashrc.
    ?</pre>

    To enable the docker-machine shell prompt, add $(__docker_machine_ps1) to your PS1 setting in ~/.bashrc.

<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="bash" contenteditable="false" cid="n64" mdtype="fences" style="font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-indent: 0px; text-transform: none; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); border: 1px solid rgb(231, 234, 237); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; padding: 8px 1em 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; caret-color: rgb(51, 51, 51); color: rgb(51, 51, 51); position: relative !important;">PS1='[\u@\h \W(__docker_machine_ps1)]\ '</pre>

Get Start with Docker-Machine

Create a machine

List available machines

docker-machine ls

Create a Machine in VMwareFusion on MacOS

docker-machine create --driver vmwarefusion default

the name of Machine is default

Get the environment commands for Your new VM.

<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="" contenteditable="false" cid="n99" mdtype="fences" style="font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-indent: 0px; text-transform: none; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); border: 1px solid rgb(231, 234, 237); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; padding: 8px 1em 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; caret-color: rgb(51, 51, 51); color: rgb(51, 51, 51); position: relative !important;">$ docker-machine env default
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://172.16.62.130:2376"
export DOCKER_CERT_PATH="/Users/<yourusername>/.docker/machine/machines/default"
export DOCKER_MACHINE_NAME="default"

Run this command to configure your shell:

eval "$(docker-machine env default)"</pre>

these information is used to set Env to connect to this docker machine

Set Env

This sets environment variables for the current shell that the Docker client reads which specify the TLS settings. You need to do this each time you open a new shell or restart your machine.

<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="" contenteditable="false" cid="n105" mdtype="fences" style="font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-indent: 0px; text-transform: none; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); border: 1px solid rgb(231, 234, 237); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; padding: 8px 1em 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; caret-color: rgb(51, 51, 51); color: rgb(51, 51, 51); position: relative !important;">eval "(docker-machine env default)" #defaut is vm's name</pre>

Unset Env**

Run eval $(docker-machine env -u) to unset all DOCKER variables in the current shell.

Start and Stop machines

<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="bash" contenteditable="false" cid="n130" mdtype="fences" style="font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-indent: 0px; text-transform: none; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); border: 1px solid rgb(231, 234, 237); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; padding: 8px 1em 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; caret-color: rgb(51, 51, 51); color: rgb(51, 51, 51); position: relative !important;"> docker-machinestopdefault docker-machinestartdefault</pre>

Use Docker-Machine to provision hosts on cloud providers

  • Amazon Web Services

<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="" contenteditable="false" cid="n141" mdtype="fences" style="font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-indent: 0px; text-transform: none; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); border: 1px solid rgb(231, 234, 237); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; padding: 8px 1em 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; caret-color: rgb(51, 51, 51); color: rgb(51, 51, 51); position: relative !important;">$ docker-machine create --driver amazonec2 --amazonec2-access-key AKI******* --amazonec2-secret-key 8T93C******* aws-sandbox</pre>

  • Generic Linux Hosts

<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="bash" contenteditable="false" cid="n144" mdtype="fences" style="font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-indent: 0px; text-transform: none; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); border: 1px solid rgb(231, 234, 237); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; padding: 8px 1em 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; caret-color: rgb(51, 51, 51); color: rgb(51, 51, 51); position: relative !important;">$ docker-machinecreate
--drivergeneric
--generic-ip-address=203.0.113.81
--generic-ssh-key~/.ssh/id_rsa
vm #vm is the machine's name</pre>

  • VMware Fusion

<pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="bash" contenteditable="false" cid="n193" mdtype="fences" style="font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-indent: 0px; text-transform: none; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none; box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); border: 1px solid rgb(231, 234, 237); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; padding: 8px 1em 6px 0px; margin-bottom: 15px; margin-top: 15px; width: inherit; caret-color: rgb(51, 51, 51); color: rgb(51, 51, 51); position: relative !important;">$ docker-machinecreate --drivervmwarefusion vm</pre>

--vmwarefusion-boot2docker-url: URL for boot2docker image.

--vmwarefusion-cpu-count: Number of CPUs for the machine (-1 to use the number of CPUs available)

--vmwarefusion-disk-size: Size of disk for host VM (in MB).

--vmwarefusion-memory-size: Size of memory for host VM (in MB).

--vmwarefusion-no-share: Disable the mount of your home directory.

  • VMware vSphere

  • <pre spellcheck="false" class="md-fences md-end-block md-fences-with-lineno ty-contain-cm modeLoaded" lang="" contenteditable="false" cid="n222" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); border: 1px solid rgb(231, 234, 237); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; padding: 8px 1em 6px 0px; margin-bottom: 15px; margin-top: 0px; width: inherit; position: relative !important;">docker-machine create --driver vmwarevsphere --vmwarevsphere-username=user --vmwarevsphere-password=SECRET vm</pre>

Command Line

  • docker-machine active

    See which machine is “active” (a machine is considered active if the DOCKER_HOST environment variable points to it).

  • docker-machine config Name

    print the connection config for machine

  • docker-machine inspect Name

    print the info of the Machine by JSON format

  • docker-machine env {Name | -u}

    display the ENV of the specified machine

    display the Unset ENV info

  • docker-machine ip Name

    get the machine's ip address

  • docker-machine url NAME

    get the URL of the machine deamon

  • docker-machine kill NAME

    Kill a machine

  • docker-machine ls

    list machines

  • docker-machine restart NAME

    restart a machine

  • docker-machine rm NAME

    remove a machine

  • docker-machine ssh NAME

    ssh to a machine

    we can also use this command to excute a remote command:

    docker-machine ssh NAME COMMAND

  • docker-machine scp A B

    copy files between machines

  • docker-machine mount NAME:/home/Dir1 LocalDir1

    mount the specified dir of the machine to local dir

    --unmount, -u Unmount instead of mount

  • docker-machine start NAME

    start a machine

  • docker-machine stop NAME

    stop the machine

  • docker-machine status NAME

    get the status of a machine

  • docker-machine upgrade NAME

    Upgrade a machine to the latest version of Docker

  • docker-machine version

    show the docker-machine version or a machine docker version

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末豪治,一起剝皮案震驚了整個(gè)濱河市洞拨,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌负拟,老刑警劉巖烦衣,帶你破解...
    沈念sama閱讀 218,036評論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異掩浙,居然都是意外死亡花吟,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,046評論 3 395
  • 文/潘曉璐 我一進(jìn)店門涣脚,熙熙樓的掌柜王于貴愁眉苦臉地迎上來示辈,“玉大人,你說我怎么就攤上這事遣蚀。” “怎么了纱耻?”我有些...
    開封第一講書人閱讀 164,411評論 0 354
  • 文/不壞的土叔 我叫張陵芭梯,是天一觀的道長。 經(jīng)常有香客問我弄喘,道長玖喘,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,622評論 1 293
  • 正文 為了忘掉前任蘑志,我火速辦了婚禮累奈,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘急但。我一直安慰自己澎媒,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,661評論 6 392
  • 文/花漫 我一把揭開白布波桩。 她就那樣靜靜地躺著戒努,像睡著了一般。 火紅的嫁衣襯著肌膚如雪镐躲。 梳的紋絲不亂的頭發(fā)上储玫,一...
    開封第一講書人閱讀 51,521評論 1 304
  • 那天侍筛,我揣著相機(jī)與錄音,去河邊找鬼撒穷。 笑死匣椰,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的端礼。 我是一名探鬼主播窝爪,決...
    沈念sama閱讀 40,288評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼齐媒!你這毒婦竟也來了蒲每?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,200評論 0 276
  • 序言:老撾萬榮一對情侶失蹤喻括,失蹤者是張志新(化名)和其女友劉穎邀杏,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體唬血,經(jīng)...
    沈念sama閱讀 45,644評論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡望蜡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,837評論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了拷恨。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片脖律。...
    茶點(diǎn)故事閱讀 39,953評論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖腕侄,靈堂內(nèi)的尸體忽然破棺而出小泉,到底是詐尸還是另有隱情,我是刑警寧澤冕杠,帶...
    沈念sama閱讀 35,673評論 5 346
  • 正文 年R本政府宣布微姊,位于F島的核電站,受9級特大地震影響分预,放射性物質(zhì)發(fā)生泄漏兢交。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,281評論 3 329
  • 文/蒙蒙 一笼痹、第九天 我趴在偏房一處隱蔽的房頂上張望配喳。 院中可真熱鬧,春花似錦凳干、人聲如沸晴裹。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,889評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽息拜。三九已至,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間少欺,已是汗流浹背喳瓣。 一陣腳步聲響...
    開封第一講書人閱讀 33,011評論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留赞别,地道東北人畏陕。 一個(gè)月前我還...
    沈念sama閱讀 48,119評論 3 370
  • 正文 我出身青樓,卻偏偏與公主長得像仿滔,于是被迫代替她去往敵國和親惠毁。 傳聞我的和親對象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,901評論 2 355

推薦閱讀更多精彩內(nèi)容