乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      【實(shí)戰(zhàn)】Docker Machine + Compose + Swarm

       浸心閣 2016-02-15
      本文的案例結(jié)合了Docker的三大編排工具Docker Machine、Compose與Swarm,值得讀者們參閱。

      Docker現(xiàn)在已經(jīng)推出了一些新的命令行工具,這些工具可以簡(jiǎn)單的編排(orchestration )Docker實(shí)例、集群以及容器管理。它們是:

      這三種技術(shù)中,Swarm目前不適合在生產(chǎn)中使用,因此在這篇文章中我不會(huì)講關(guān)于它的太多細(xì)節(jié)。

      Docker Machine

      對(duì)于直接下載預(yù)編譯的二進(jìn)制文件來(lái)說(shuō),我決定使用 Homebrew(OS X的管理包工具)
      1
      2
      3
      4
      5
      6
      7
      # Make sure everything is up-to-date
      brew update
      brew doctor
      brew cask update
      brew cask doctor
      # install docker-machine
      brew cask install docker-machine

      這樣就安裝了docker-machine。
      1
      2
      3
      4
      5
      $  docker-machine -v
      docker-machine version 0.1.0
      $  docker-machine ls
      NAME   ACTIVE   DRIVER   STATE   URL   SWARM

      我已經(jīng)安裝了 VirtualBox,并且要?jiǎng)?chuàng)建一個(gè)叫“testing”的虛擬機(jī):
      1
      2
      3
      4
      5
      6
      7
      $  docker-machine create --driver virtualbox testing
      INFO[0000] Creating SSH key...                          
      INFO[0000] Creating VirtualBox VM...                    
      INFO[0006] Starting VirtualBox VM...                    
      INFO[0006] Waiting for VM to start...                   
      INFO[0038] "testing" has been created and is now the active machine. 
      INFO[0038] To point your Docker client at it, run this in your shell: $(docker-machine env testing)

      docker-machine使用幾個(gè)命令來(lái)幫助你連接到本地安裝的Docker客戶端:
      1
      2
      3
      4
      5
      6
      $  docker-machine env testing
      export DOCKER_TLS_VERIFY=yes
      export DOCKER_CERT_PATH=/Users/russ/.docker/machine/machines/testing
      export DOCKER_HOST=tcp://192.168.99.100:2376
      $  docker-machine config testing
      --tls --tlscacert=/Users/russ/.docker/machine/machines/testing/ca.pem --tlscert=/Users/russ/.docker/machine/machines/testing/cert.pem --tlskey=/Users/russ/.docker/machine/machines/testing/key.pem -H="tcp://192.168.99.100:2376

      我現(xiàn)在啟用了一個(gè)虛擬機(jī)并準(zhǔn)備使用Docker。
      1
      2
      3
      $  docker-machine ls
      NAME      ACTIVE   DRIVER       STATE     URL                         SWARM
      testing   *        virtualbox   Running   tcp://192.168.99.100:2376

      和其他新安裝的一樣,讓我們運(yùn)行一個(gè)“Hello World”:
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      $  docker $(docker-machine config testing) run busybox echo hello world
      Unable to find image 'busybox:latest' locally
      511136ea3c5a: Pull complete 
      df7546f9f060: Pull complete 
      ea13149945cb: Pull complete 
      4986bf8c1536: Pull complete 
      busybox:latest: The image you are pulling has been verified. Important: image verification is a tech preview feature and should not be relied on to provide security.
      Status: Downloaded newer image for busybox:latest
      hello world

      最后,你可以使用docker-machie ssh machine-name命令SSH到虛擬機(jī):
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      $  docker-machine ssh testing
      Boot2Docker version 1.5.0, build master : a66bce5 - Tue Feb 10 23:31:27 UTC 2015
      Docker version 1.5.0, build a8a31ef
      docker@testing:~$ uname -a
      Linux testing 3.18.5-tinycore64 #1 SMP Sun Feb 1 06:02:30 UTC 2015 x86_64 GNU/Linux
      docker@testing:~$ cat /etc/*release
      NAME=Boot2Docker
      VERSION=1.5.0
      ID=boot2docker
      ID_LIKE=tcl
      VERSION_ID=1.5.0
      PRETTY_NAME="Boot2Docker 1.5.0 (TCL 5.4); master : a66bce5 - Tue Feb 10 23:31:27 UTC 2015"
      ANSI_COLOR="1;34"
      HOME_URL="http://"
      SUPPORT_URL="https://github.com/boot2docker/boot2docker"
      BUG_REPORT_URL="https://github.com/boot2docker/boot2docker/issues"
      docker@testing:$ exit
      $  

      太棒了,我現(xiàn)在有一個(gè)虛擬機(jī)運(yùn)行在我的電腦上,接下來(lái)呢?

      設(shè)計(jì)docker-machine就是和以下公有和私有的云服務(wù)提供商(以后會(huì)添加更多)一起使用的。
      • Amazon EC2
      • Microsoft Azure
      • Digital Ocean
      • Google Compute Engine
      • Rackspace
      • SoftLayer
      • OpenStack
      • VMWare vCloud Air
      • VMWare vSphere

      讓我們使用docker-machine來(lái)啟用一個(gè)Digital Ocean的實(shí)例。你需要生成一個(gè)Personal Access Token。一旦用token啟用機(jī)子就會(huì)像下面所示一樣:
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      $  docker-machine create \
      →     --driver digitalocean \
      →     --digitalocean-access-token cdb81ed0575b5a8d37cea0d06c9690daa074b1276892fc8473bdda97eb7c65ae \
      →     dotesting
      INFO[0000] Creating SSH key...                          
      INFO[0000] Creating Digital Ocean droplet...            
      INFO[0004] Waiting for SSH...                           
      INFO[0071] Configuring Machine...                       
      INFO[0120] "dotesting" has been created and is now the active machine. 
      INFO[0120] To point your Docker client at it, run this in your shell: $(docker-machine env dotesting) 

      那么發(fā)生了什么呢?docker-machine訪問(wèn)我的Digital Ocean賬戶通過(guò)API并且啟用了以下配置的實(shí)例:
      • OS = Ubuntu 14.04 x64
      • RAM = 512MB
      • HDD = 20GB SSD
      • Region = NYC3

      這些默認(rèn)的配置可以通過(guò)提供更多的選項(xiàng)被修改,運(yùn)行docker-machine create --help獲取幫助查看所有帶例子的選項(xiàng)。

      一旦實(shí)例開啟,docker-machine通過(guò)SSH連接到安裝、配置以及開啟的最新的Docker上。

      所以,我們現(xiàn)在有兩臺(tái)Machines,一個(gè)在本地,一個(gè)在Digital Ocean上。
      1
      2
      3
      4
      $  docker-machine ls
      NAME        ACTIVE   DRIVER         STATE     URL                         SWARM
      dotesting   *        digitalocean   Running   tcp://45.55.134.248:2376    
      testing              virtualbox     Running   tcp://192.168.99.100:2376  

      讓我們?cè)俅芜\(yùn)行“Hello World”,但是這次使用剛才啟動(dòng)的那個(gè)實(shí)例:
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      $  docker $(docker-machine config dotesting) run busybox echo hello world
      Unable to find image 'busybox:latest' locally
      511136ea3c5a: Pull complete 
      df7546f9f060: Pull complete 
      ea13149945cb: Pull complete 
      4986bf8c1536: Pull complete 
      busybox:latest: The image you are pulling has been verified. Important: image verification is a tech preview feature and should not be relied on to provide security.
      Status: Downloaded newer image for busybox:latest
      hello world

      并且SSH到那個(gè)機(jī)器中:
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      $  docker-machine ssh dotesting
      Welcome to Ubuntu 14.04.1 LTS (GNU/Linux 3.13.0-43-generic x86_64)
      Documentation:  https://help.ubuntu.com/
      System information as of Sat Mar 21 07:24:02 EDT 2015
      System load:  0.43               Processes:              72
      Usage of /:   11.4% of 19.56GB   Users logged in:        0
      Memory usage: 12%                IP address for eth0:    45.55.134.248
      Swap usage:   0%                 IP address for docker0: 172.17.42.1
      Graph this data and manage this system at:
      https://landscape.canonical.com/
      root@dotesting:~# docker images
      REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
      busybox             latest              4986bf8c1536        11 weeks ago        2.433 MB
      root@dotesting:~# docker ps -a
      CONTAINER ID        IMAGE               COMMAND              CREATED             STATUS                     PORTS               NAMES
      b8a83077d858        busybox:latest      "echo hello world"   4 minutes ago       Exited (0) 4 minutes ago                       kickass_almeida     
      root@dotesting:~# exit
      logout
      $  

      最終,你可以使用docker-mashie stop machine-name和docker-mashie rm machine-name來(lái)停止和移除machines。請(qǐng)注意當(dāng)使用rm時(shí),是不會(huì)提示你是否確定刪除。

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      $  docker-machine ls
      NAME        ACTIVE   DRIVER         STATE     URL                         SWARM
      dotesting   *        digitalocean   Running   tcp://45.55.134.248:2376    
      testing              virtualbox     Running   tcp://192.168.99.100:2376   
      $  docker-machine stop dotesting
      $  docker-machine ls
      NAME        ACTIVE   DRIVER         STATE     URL                         SWARM
      dotesting   *        digitalocean   Stopped   tcp://45.55.134.248:2376    
      testing              virtualbox     Running   tcp://192.168.99.100:2376   
      $  docker-machine rm dotesting
      $  docker-machine ls
      NAME      ACTIVE   DRIVER       STATE     URL                         SWARM
      testing            virtualbox   Running   tcp://192.168.99.100:2376   
      $  

      總結(jié),以上就是docker-machie的總覽。正如你看到的,它確實(shí)很方便在很多不同的供應(yīng)商中來(lái)引導(dǎo)Docker服務(wù)實(shí)例,并且使用一個(gè)本地machine命令就可以操控他們。

      Docker Compose

      Docker開始充滿生機(jī)是因?yàn)橛辛薋ig, 這是我曾在以前的文章中寫到過(guò),當(dāng)前版本并沒(méi)有添加太多的新功能,但它開始奠定了與docker-swarm工作的基礎(chǔ),單擊 這里查看詳細(xì)日志。

      像docker-machine一樣,我使用Homebrew公式安裝docker-compose。
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      $  brew install docker-compose
      ==> Downloading https://homebrew.bintray.com/bottles/fig-1.1.0.yosemite.bottle.1.tar.gz<h6>
          ############################################################ 100.0%</h6>
      ==> Pouring fig-1.1.0.yosemite.bottle.1.tar.gz
      ==> Caveats
      Bash completion has been installed to:
      /usr/local/etc/bash_completion.d
      ==> Summary
      /usr/local/Cellar/fig/1.1.0: 186 files, 2.2M
      $  

      然后,使用docker-machine創(chuàng)建一個(gè)Docker服務(wù)實(shí)例:
      1
      2
      3
      4
      5
      6
      7
      $  docker-machine create --driver virtualbox compose
      INFO[0001] Creating SSH key...                          
      INFO[0001] Creating VirtualBox VM...                    
      INFO[0007] Starting VirtualBox VM...                    
      INFO[0008] Waiting for VM to start...                   
      INFO[0041] "compose" has been created and is now the active machine. 
      INFO[0041] To point your Docker client at it, run this in your shell: $(docker-machine env compose) 

      因?yàn)閐ocker-compose不直接與docker-machine交互,我們需要告訴docker客戶端那些剛剛啟動(dòng)的服務(wù)器實(shí)例的詳細(xì)信息。
      1
      $  $(docker-machine env compose)

      此命令注入所需Docker客戶端的環(huán)境變量來(lái)連接到服務(wù)實(shí)例,要看到他們,你只需運(yùn)行docker-machine env machine-name。
      1
      2
      3
      4
      $  docker-machine env compose
      export DOCKER_TLS_VERIFY=yes
      export DOCKER_CERT_PATH=/Users/russ/.docker/machine/machines/compose
      export DOCKER_HOST=tcp://192.168.99.100:2376

      往后它就像Fig一樣,除了fig.yml文件現(xiàn)在應(yīng)該改為docker-compose.yml,在我以前的博文里有一個(gè)fig.yml文件描述:
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      web:  
      image: russmckendrick/nginx-php
      volumes:
      - ./web:/var/www/html/
      ports:
      - 80:80
      environment:
      PHP_POOL: mywebsite
      links:
      - db:db
      db:  
      image: russmckendrick/mariadb
      ports:
      - 3306
      privileged: true
      environment:
      MYSQL_ROOT_PASSWORD: wibble
      MYSQL_DATABASE: wibble
      MYSQL_USER: wibble
      MYSQL_PASSWORD: wibble

      它啟用兩個(gè)容器并且把它們連接到一起,還有在Nginx容器內(nèi)的/var/www/html被掛載到host的./web文件夾下。我準(zhǔn)備運(yùn)行docker-compose命令的文件夾的結(jié)構(gòu)是這樣的:
      1
      2
      3
      4
      5
      6
      7
      $  tree -a
      .
      ├── \[russ      356]  docker-compose.yml
      └── \[russ      102]  web
      └── \[russ       67]  index.php
      1 directory, 2 files

      開始我要拉取需要啟用的鏡像,你可以忽略此部分。
      1
      2
      3
      $  docker-compose pull
      Pulling db (russmckendrick/mariadb:latest)...
      Pulling web (russmckendrick/nginx-php:latest)...

      現(xiàn)在鏡像已經(jīng)被拉取下來(lái),是時(shí)候開啟容器了:
      1
      2
      3
      $  docker-compose up -d
      Creating example_db_1...
      Creating example_web_1...

      我們現(xiàn)在有了兩個(gè)正在運(yùn)行的容器:
      1
      2
      3
      4
      5
      $  docker-compose ps
      Name             Command         State            Ports          
      ----------------------------------------------------------------
      example_db_1    /usr/local/bin/run   Up      0.0.0.0:49154->3306/tcp 
      example_web_1   /usr/local/bin/run   Up      0.0.0.0:80->80/tcp   

      你也可以打開瀏覽器:
      1
      open http://$(docker-machine ip)

      在我的例子中我看到PHPinfo()頁(yè)面,如下:
      【實(shí)戰(zhàn)】Docker Machine + Compose + Swarm

      一旦容器開啟,你可以使用docker exec來(lái)連接到容器內(nèi)部:
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      $  docker exec -it example_web_1 bash
      [root@997bbe6b5c80 /]# ps aux
      USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
      root         1  0.2  1.5 115200 15360 ?        Ss   13:59   0:01 /usr/bin/python /usr/bin/supervisord -n
      root        16  0.0  3.2 382876 33624 ?        S    13:59   0:00 php-fpm: master process (/etc/php-fpm.conf)
      root        17  0.0  0.2 110016  2096 ?        Ss   13:59   0:00 nginx: master process nginx
      nginx       18  0.0  0.5 110472  5568 ?        S    13:59   0:00 nginx: worker process
      webserv+    19  0.0  1.5 383132 16284 ?        S    13:59   0:00 php-fpm: pool mywebsite
      webserv+    20  0.0  0.8 382876  8848 ?        S    13:59   0:00 php-fpm: pool mywebsite
      webserv+    21  0.0  0.8 382876  8848 ?        S    13:59   0:00 php-fpm: pool mywebsite
      webserv+    22  0.0  0.8 382876  8848 ?        S    13:59   0:00 php-fpm: pool mywebsite
      webserv+    23  0.0  0.8 382876  8852 ?        S    13:59   0:00 php-fpm: pool mywebsite
      root        95  0.0  0.4  91540  4740 ?        Ss   13:59   0:00 /usr/libexec/postfix/master -w
      postfix     97  0.0  0.6  91712  6508 ?        S    13:59   0:00 qmgr -l -t unix -u
      postfix    200  0.0  0.6  91644  6232 ?        S    14:05   0:00 pickup -l -t unix -u
      root       234  2.3  0.2  11748  2968 ?        S    14:07   0:00 bash
      root       250  1.0  1.1 110012 11616 ?        S    14:07   0:00 nginx
      root       251  0.0  0.2  19756  2212 ?        R+   14:07   0:00 ps aux
      [root@997bbe6b5c80 /]# exit
      exit
      $  

      最后你可以停止以及移除容器,當(dāng)然還有Docker實(shí)例:
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      $  docker-compose stop && docker-compose rm --force
      Stopping example_web_1...
      Stopping example_db_1...
      Going to remove example_web_1, example_db_1
      Removing example_db_1...
      Removing example_web_1...
      $  docker-machine rm compose
      $  docker-machine ls
      NAME   ACTIVE   DRIVER   STATE   URL   SWARM
      $  

      Docker Swarm

      在進(jìn)一步討論之前,先看下官方文檔的警告:

      警告:Swarm當(dāng)前是beta版本,因此后期可能會(huì)有變化。我們還不推薦在生產(chǎn)環(huán)境中使用。
      現(xiàn)在讓我們使用Homebrew來(lái)安裝docker-swarm:
      1
      2
      3
      4
      5
      $  brew install docker-swarm
      ==> Downloading https://homebrew.bintray.com/bottles/docker-swarm-0.1.0.yosemite.bottle.tar.gz<h6>
          ############################################################ 100.0%</h6>
      ==> Pouring docker-swarm-0.1.0.yosemite.bottle.tar.gz
      /usr/local/Cellar/docker-swarm/0.1.0: 4 files, 8.7M

      因?yàn)槲覀円呀?jīng)安裝了docker-machine,我將要使用它在本地創(chuàng)建一個(gè)集群。首先,我們需要啟動(dòng)一個(gè)實(shí)例并運(yùn)行swarm容器:
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      $  docker-machine ls
      NAME   ACTIVE   DRIVER   STATE   URL   SWARM
      $  docker-machine create -d virtualbox local
      INFO[0001] Creating SSH key...                          
      INFO[0001] Creating VirtualBox VM...                    
      INFO[0006] Starting VirtualBox VM...                    
      INFO[0006] Waiting for VM to start...                   
      INFO[0039] "local" has been created and is now the active machine. 
      INFO[0039] To point your Docker client at it, run this in your shell: $(docker-machine env local
      $   $(docker-machine env local
      $  docker run swarm create
      Unable to find image 'swarm:latest' locally
      511136ea3c5a: Pull complete 
      ae115241d78a: Pull complete 
      f49087514537: Pull complete 
      fff73787bd9f: Pull complete 
      97c8f6e912d7: Pull complete 
      33f9d1e808cf: Pull complete 
      62860d7acc87: Pull complete 
      bf8b6923851d: Pull complete 
      swarm:latest: The image you are pulling has been verified. Important: image verification is a tech preview feature and should not be relied on to provide security.
      Status: Downloaded newer image for swarm:latest
      63e7a1adb607ce4db056a29b1f5d30cf
      $  

      正如你所見,當(dāng)容器啟動(dòng)時(shí),我得到了一個(gè)token:63e7a1adb607ce4db056a29b1f5d30cf,我將要用它來(lái)添加更多的節(jié)點(diǎn),但是首先我們需要?jiǎng)?chuàng)建一個(gè)Swarm master:
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      $  docker-machine create \
      →     -d virtualbox \
      →     --swarm \
      →     --swarm-master \
      →     --swarm-discovery token://63e7a1adb607ce4db056a29b1f5d30cf \
      →     swarm-master
      INFO[0000] Creating SSH key...                          
      INFO[0000] Creating VirtualBox VM...                    
      INFO[0006] Starting VirtualBox VM...                    
      INFO[0006] Waiting for VM to start...                   
      INFO[0038] Configuring Swarm...                         
      INFO[0043] "swarm-master" has been created and is now the active machine. 
      INFO[0043] To point your Docker client at it, run this in your shell: $(docker-machine env swarm-master)

      然后,我們需要連接Docker客戶端到Swarm上,這就需要將--swarm添加到$(docker-machine env machine-name)命令上:
      1
      $  $(docker-machine env --swarm swarm-master)

      現(xiàn)在讓我們添加另一個(gè)節(jié)點(diǎn):
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      $  docker-machine create \
      →     -d virtualbox \
      →     --swarm \
      →     --swarm-discovery token://63e7a1adb607ce4db056a29b1f5d30cf  \
      →     swarm-node-00
      INFO[0000] Creating SSH key...                          
      INFO[0000] Creating VirtualBox VM...                    
      INFO[0006] Starting VirtualBox VM...                    
      INFO[0006] Waiting for VM to start...                   
      INFO[0039] Configuring Swarm...                         
      INFO[0048] "swarm-node-00" has been created and is now the active machine. 

      我們現(xiàn)在有了2個(gè)節(jié)點(diǎn)的集群 - “swarm-master”:
      1
      2
      3
      4
      5
      $  docker-machine ls
      NAME            ACTIVE   DRIVER       STATE     URL                         SWARM
      local                    virtualbox   Running   tcp://192.168.99.100:2376   
      swarm-master             virtualbox   Running   tcp://192.168.99.101:2376   swarm-master (master)
      swarm-node-00   *        virtualbox   Running   tcp://192.168.99.102:2376   swarm-master

      使用docker info來(lái)獲取更多有關(guān)集群的信息:
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      $  docker info
      Containers: 3
      Nodes: 2
      swarm-master: 192.168.99.101:2376
      └ Containers: 2
      └ Reserved CPUs: 0 / 4
      └ Reserved Memory: 0 B / 999.9 MiB
      swarm-node-00: 192.168.99.102:2376
      └ Containers: 1
      └ Reserved CPUs: 0 / 4
      └ Reserved Memory: 0 B / 999.9 MiB

      太棒了,但這意味著什么?

      讓我們拉取一些鏡像:
      1
      2
      $  docker -H 192.168.99.101:2376 pull redis
      $  docker -H 192.168.99.102:2376 pull mysql

      注意到我是如何在“swarm-master”上拉取redis鏡像以及在swarm-node-00上拉取mysql的,現(xiàn)在我可以保證容器只在有鏡像的那個(gè)節(jié)點(diǎn)上啟用:
      1
      2
      3
      4
      5
      6
      7
      8
      $  docker run -d --name redis1 -e affinity:image==redis redis
      af66148bbbc8dcd799d82448dfd133b968d34eb7066a353108bf909ea3324a58
      $  docker run -d --name mysql -e affinity:image==mysql -e MYSQL_ROOT_PASSWORD=mysecretpassword -d mysql 
      70b2d93d6f83aa99f5ad4ebe5037e228a491a4b570609840f3f4be9780c33587
      $  docker ps
      CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS                  PORTS               NAMES
      70b2d93d6f83        mysql:latest        "/entrypoint.sh mysq   3 seconds ago       Up Less than a second   3306/tcp            swarm-node-00/mysql   
      af66148bbbc8        redis:latest        "/entrypoint.sh redi   2 minutes ago       Up 2 minutes            6379/tcp            swarm-master/redis1  

      另一個(gè)例子是使用節(jié)點(diǎn)的端口,讓我們?cè)趦蓚€(gè)節(jié)點(diǎn)上都拉取我的nginx-php鏡像:
      1
      2
      $  docker -H 192.168.99.101:2376 pull russmckendrick/nginx-php
      $  docker -H 192.168.99.102:2376 pull russmckendrick/nginx-php

      現(xiàn)在,讓我們啟用一個(gè)容器并綁定到80端口。
      1
      2
      $  docker run -d -p 80:80 russmckendrick/nginx-php
      2d066b2ccf28d2a1fa9edad8ac7b065266f29ecb49a8753b972780051ff83587

      再有:
      1
      2
      $  docker run -d -p 80:80 russmckendrick/nginx-php
      40f5fee257bb2546a639a5dc5c2d30f8fa0ac169145e431c534f85d8db51357f

      你會(huì)說(shuō)這沒(méi)什么特別的???正常來(lái)說(shuō),當(dāng)試圖啟動(dòng)第二個(gè)容器時(shí),你會(huì)得到如下信息因?yàn)槟悴挥脤⑼粋€(gè)端口綁定到兩個(gè)容器上:
      1
      2
      $  docker run -d -p 80:80 russmckendrick/nginx-php
      FATA[0000] Error response from daemon: unable to find a node with port 80 available 

      然而,在集群的情況下,因?yàn)镈ocker知道集群節(jié)點(diǎn)運(yùn)行的是什么以及哪些端口是在使用的。Docker可以簡(jiǎn)單地通過(guò)Swarm在“swarm-node-00”上啟動(dòng)容器并且它知道“swarm-master”已經(jīng)使用了80端口:
      1
      2
      3
      4
      5
      6
      $  docker ps
      CONTAINER ID        IMAGE                             COMMAND                CREATED             STATUS                  PORTS                       NAMES
      40f5fee257bb        russmckendrick/nginx-php:latest   "/usr/local/bin/run"   4 seconds ago       Up Less than a second   192.168.99.101:80->80/tcp   swarm-master/elated_einstein   
      2d066b2ccf28        russmckendrick/nginx-php:latest   "/usr/local/bin/run"   8 seconds ago       Up Less than a second   192.168.99.102:80->80/tcp   swarm-node-00/drunk_mestorf    
      70b2d93d6f83        mysql:latest                      "/entrypoint.sh mysq   26 minutes ago      Up 26 minutes           3306/tcp                    swarm-node-00/mysql            
      af66148bbbc8        redis:latest                      "/entrypoint.sh redi   29 minutes ago      Up 29 minutes           6379/tcp                    swarm-master/redis1 

      所有這一切都沒(méi)有提示或特殊的命令行,它的幫助僅僅是用它來(lái)做到這些。

      正如你所看到的,docker-swarm仍然有非常大的發(fā)展?jié)摿?,但也有一些不如意的地方,如容器不能夠跨?jié)點(diǎn)通訊。然而,伴隨著 (他們使用Open vSwitch開發(fā)了一個(gè)基于軟件定義網(wǎng)絡(luò)解決方案的容器)的加入,我想用不了多長(zhǎng)時(shí)間這個(gè)問(wèn)題就能得到解決。

      最后,讓我們刪除在運(yùn)行的實(shí)例:
      1
      $  docker-machine rm local swarm-master swarm-node-00

      就這樣吧,期待在未來(lái)的幾個(gè)月這些工具的更新,我也會(huì)進(jìn)一步跟進(jìn)。

      原文:Docker Machine, Compose & Swarm (翻譯:田浩浩 校對(duì):李穎杰)

      來(lái)自:http:///article/275

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多