Docker Demo on Docker
install docker-machine
01 02 03 | $ curl -L https: //github .com /docker/machine/releases/download/v0 .10.0 /docker-machine- ` uname -s`-` uname -m` > /tmp/docker-machine && chmod +x /tmp/docker-machine && sudo cp /tmp/docker-machine /usr/local/bin/docker-machine |
create manager & worker
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 | $ docker-machine create --driver virtualbox manager Running pre-create checks... Creating machine... (manager) Copying /Users/victoria/ .docker /machine/cache/boot2docker .iso to /Users/victoria/ .docker /machine/machines/manager/boot2docker .iso... (manager) Creating VirtualBox VM... (manager) Creating SSH key... (manager) Starting the VM... (manager) Check network to re-create if needed... (manager) Waiting for an IP... Waiting for machine to be running, this may take a few minutes... Detecting operating system of created instance... Waiting for SSH to be available... Detecting the provisioner... Provisioning with boot2docker... Copying certs to the local machine directory... Copying certs to the remote machine... Setting Docker configuration on the remote daemon... Checking connection to Docker... Docker is up and running! To see how to connect your Docker Client to the Docker Engine running on this virtual machine, run: docker-machine env manager |
Verify machines are running and get IP addresses
01 02 03 04 | $ docker-machine ls NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS manager * virtualbox Running tcp: //192 .168.99.100:2376 v17.03.0-ce worker - virtualbox Running tcp: //192 .168.99.101:2376 v17.03.0-ce |
MANAGE THE MACHINES FROM A PRE-CONFIGURED SHELL
01 02 03 04 05 06 07 08 | $ docker-machine env manager export DOCKER_TLS_VERIFY= "1" export DOCKER_HOST= "tcp://192.168.99.100:2376" export DOCKER_CERT_PATH= "/Users/victoriabialas/.docker/machine/machines/manager" export DOCKER_MACHINE_NAME= "manager" export DOCKER_API_VERSION= "1.25" # Run this command to configure your shell: # eval $(docker-machine env manager) |
SSH INTO A MACHINE
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 | $ docker-machine ssh manager ## . ## ## ## == ## ## ## ## ## === / "" "" "" "" "" "" "" "" "\___/ === ~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ / ===- ~~~ \______ o __/ \ \ __/ \____\_______/ _ _ ____ _ _ | |__ ___ ___ | |_|___ \ __| | ___ ___| | _____ _ __ | '_ \ / _ \ / _ \| __| __) / _` |/ _ \ / __| |/ / _ \ ' __| | |_) | (_) | (_) | |_ / __/ (_| | (_) | (__| < __/ | |_.__/ \___/ \___/ \__|_____\__,_|\___/ \___|_|\_\___|_| WARNING: this is a build from test .docker.com, not a stable release. Boot2Docker version 1.13.0-rc6, build HEAD : 5ab2289 - Wed Jan 11 23:37:52 UTC 2017 Docker version 1.13.0-rc6, build 2f2d055 |
Create a swarm
Initialize the swarm
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 | $ docker-machine ssh manager ## . ## ## ## == ## ## ## ## ## === / "" "" "" "" "" "" "" "" "\___/ === ~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ / ===- ~~~ \______ o __/ \ \ __/ \____\_______/ _ _ ____ _ _ | |__ ___ ___ | |_|___ \ __| | ___ ___| | _____ _ __ | '_ \ / _ \ / _ \| __| __) / _` |/ _ \ / __| |/ / _ \ ' __| | |_) | (_) | (_) | |_ / __/ (_| | (_) | (__| < __/ | |_.__/ \___/ \___/ \__|_____\__,_|\___/ \___|_|\_\___|_| WARNING: this is a build from test .docker.com, not a stable release. Boot2Docker version 1.13.0-rc7, build HEAD : b2cde29 - Sat Jan 14 00:29:39 UTC 2017 Docker version 1.13.0-rc7, build 48a9e53 |
Initialize a swarm
01 02 03 04 05 06 07 08 09 10 | docker@manager:~$ docker swarm init --advertise-addr 192.168.99.100 Swarm initialized: current node (2tjrasfqfu945b7n4753374sw) is now a manager. To add a worker to this swarm, run the following command : docker swarm join \ --token SWMTKN-1-144pfsupfo25h43zzr6b6bghjson8uedxjsndo5vuehqlyarsk-9k4q84axm008whv9zl4a8m8ct \ 192.168.99.100:2377 To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions. |
Add a worker node to the swarm
Log into the worker machine.
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 | $ docker-machine ssh worker ## . ## ## ## == ## ## ## ## ## === / "" "" "" "" "" "" "" "" "\___/ === ~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ / ===- ~~~ \______ o __/ \ \ __/ \____\_______/ _ _ ____ _ _ | |__ ___ ___ | |_|___ \ __| | ___ ___| | _____ _ __ | '_ \ / _ \ / _ \| __| __) / _` |/ _ \ / __| |/ / _ \ ' __| | |_) | (_) | (_) | |_ / __/ (_| | (_) | (__| < __/ | |_.__/ \___/ \___/ \__|_____\__,_|\___/ \___|_|\_\___|_| WARNING: this is a build from test .docker.com, not a stable release. Boot2Docker version 1.13.0-rc7, build HEAD : b2cde29 - Sat Jan 14 00:29:39 UTC 2017 Docker version 1.13.0-rc7, build 48a9e53 |
join
command given as the output of the swarm init
command you ran on the manager.
01 02 03 04 | docker@worker:~$ docker swarm join \ > --token SWMTKN-1-144pfsupfo25h43zzr6b6bghjson8uedxjsndo5vuehqlyarsk-9k4q84axm008whv9zl4a8m8ct \ > 192.168.99.100:2377 This node joined a swarm as a worker. |
List the nodes in the swarm
01 02 03 04 | docker@manager:~$ docker node ls ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS 2tjrasfqfu945b7n4753374sw * manager Ready Active Leader syc46yimgtyz9ljcsfqiurvp0 worker Ready Active |
作者:旭东
出处:http://www.cnblogs.com/HQFZ
关于作者:专注于微软平台项目架构、管理和企业解决方案。现主要从事WinForm、ASP.NET、WPF、WCF、等方面的项目开发、架构、管理。如有问题或建议,请不吝指教!
本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。如有问题,可以联系我,非常感谢。
如果您该文觉得不错或者对你有帮助,请点下推荐,让更多的朋友看到,谢谢!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· 展开说说关于C#中ORM框架的用法!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?