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) |
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 |
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 |
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://boot2docker.io" SUPPORT_URL= "https://github.com/boot2docker/boot2docker" BUG_REPORT_URL= "https://github.com/boot2docker/boot2docker/issues" docker@testing:$ exit $ |
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) |
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 |
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 $ |
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 $ |
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 $ |
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) |
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 |
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 $ |
警告:Swarm當前是beta版本,因此后期可能會有變化。我們還不推薦在生產(chǎn)環(huán)境中使用。現(xiàn)在讓我們使用Homebrew來安裝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 |
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 $ |
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) |
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. |
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 |
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 |