#安装docker-machine
cupid@ubuntu:~$ pwd
/home/cupid
cupid@ubuntu:~$ ls
Desktop  docker-machine-Linux-x86_64  Documents  Downloads  examples.desktop  Music  Pictures  Public  Templates  Videos
cupid@ubuntu:~$ mv docker-machine-Linux-x86_64  docker-machine
cupid@ubuntu:~$ chmod +x  docker-machine
cupid@ubuntu:~$ sudo scp docker-machine /usr/local/bin/docker-machine
cupid@ubuntu:~$ docker-machine  version  #安装成功
docker-machine version 0.12.2, build 9371605
##
cupid@ubuntu:~$ cd /etc/bash_completion.d/
cupid@ubuntu:/etc/bash_completion.d$ ls
apport_completion      git-prompt  insserv
desktop-file-validate  grub        libreoffice.sh
cupid@ubuntu:/etc/bash_completion.d$ vi docker-machine-prompt.bash
~
##添加被管理节点
1)生成ssh-key并拷贝到被管理节点
root@ubuntu:~# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
/root/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:vleIKvWOKKZLtgNiZOe2z1U13xuuYLXKReYq1/Z/O74 root@ubuntu
The key's randomart image is:
+---[RSA 2048]----+
|                 |
|                 |
|           o     |
| o .      . o .  |
|o o     So . = o |
|o. o  ..o . * o o|
|+o. .. +.  +.+ o |
|o.+.o.o..o+.=o...|
|o=..o+..o.o+..oEB|
+----[SHA256]-----+
root@ubuntu:~# ssh-copy-id 192.168.142.169
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.142.169's password: Number of key(s) added: 1Now try logging into the machine, with:   "ssh '192.168.142.169'"
and check to make sure that only the key(s) you wanted were added.root@ubuntu:~# ssh-copy-id 192.168.142.170
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.142.170 (192.168.142.170)' can't be established.
ECDSA key fingerprint is SHA256:nMYNsS3zGCBuh8jVYGG4XRieWfH0SvvAMIhz2O+bZKc.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.142.170's password: Number of key(s) added: 1Now try logging into the machine, with:   "ssh '192.168.142.170'"
and check to make sure that only the key(s) you wanted were added.
#无需输入密码可登陆169
root@ubuntu:~# ssh 192.168.142.169
Welcome to Ubuntu 16.04.2 LTS (GNU/Linux 4.10.0-28-generic x86_64)* Documentation:  https://help.ubuntu.com* Management:     https://landscape.canonical.com* Support:        https://ubuntu.com/advantage52 packages can be updated.
1 update is a security update.
2)添加被管理节点 因为是虚拟机,指定普通操作系统即可
root@ubuntu:~# docker-machine create --driver generic --generic-ip-address=192.168.142.169 host1
Creating CA: /root/.docker/machine/certs/ca.pem
Creating client certificate: /root/.docker/machine/certs/cert.pem
Running pre-create checks...
Creating machine...
(host1) No SSH key specified. Assuming an existing key at the default location.
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 ubuntu(systemd)...
Installing Docker...
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 host1
#查看添加的主机
root@ubuntu:~# docker-machine ls
NAME    ACTIVE   DRIVER    STATE     URL                          SWARM   DOCKER        ERRORS
host1   -        generic   Running   tcp://192.168.142.169:2376           v17.06.0-ce   ~
~
3)如何管理节点的docker
[root@host1:~]#echo $PS1
[\u@\h:\w$(__docker_machine_ps1)]\$
[root@host1:~]#docker-machine ls
NAME    ACTIVE   DRIVER    STATE     URL                          SWARM   DOCKER        ERRORS
host1   -        generic   Running   tcp://192.168.142.169:2376           v17.06.0-ce
host2   -        generic   Running   tcp://192.168.142.170:2376           v17.06.0-ce
#查看连接到host1需要的环境变量
[root@host1:~]#docker-machine env host1
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.142.169:2376"
export DOCKER_CERT_PATH="/root/.docker/machine/machines/host1"
export DOCKER_MACHINE_NAME="host1"
# Run this command to configure your shell:
# eval $(docker-machine env host1)
#查看连接到host2需要的环境变量
[root@host1:~]#docker-machine env host2
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.142.170:2376"
export DOCKER_CERT_PATH="/root/.docker/machine/machines/host2"
export DOCKER_MACHINE_NAME="host2"
# Run this command to configure your shell:
# eval $(docker-machine env host2)
#eval此环境变量即可连接到host2的docker
[root@host1:~]#eval $(docker-machine env host2)[root@host1:~ [host2]]#docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                         PORTS                    NAMES
87300fa502e3        busybox             "sh"                     About an hour ago   Exited (0) About an hour ago                            focused_cray
aea28d5d7030        busybox             "-it"                    About an hour ago   Created                                                 keen_noether
c9370139a79e        httpd               "httpd-foreground"       5 days ago          Exited (255) 2 hours ago       80/tcp                   quirky_hypatia
e5deab94f264        centos              "/bin/bash -c 'whi..."   5 days ago          Exited (255) 2 hours ago                                romantic_johnson
d19d1c95874f        registry:2          "/entrypoint.sh /e..."   5 days ago          Exited (255) 2 hours ago       0.0.0.0:5000->5000/tcp   hardcore_colden
~

转载于:https://www.cnblogs.com/wanyp/p/7257457.html

docker三剑客之docker-machine相关推荐

  1. Docker(五):Docker 三剑客之 Docker Machine

    上篇文章Docker(四):Docker 三剑客之 Docker Compose 介绍了 Docker Compose,这篇文章我们来了解 Docker Machine . Docker Machin ...

  2. Docker 三剑客之Docker Swarm

    Docker Swarm 介绍 Swarm 在 Docker 1.12 版本之前属于一个独立的项目,在 Docker 1.12 版本发布之后,该项目合并到了 Docker 中,成为 Docker 的一 ...

  3. Docker系列之五:Docker 三剑客之 Docker Swarm

    title: Docker系列之五:Docker 三剑客之 Docker Swarm categories: Docker tags: - Docker timezone: Asia/Shanghai ...

  4. docker——三剑客之Docker Machine

    Docker Machine是Docker官方三剑客项目之一,负责使用Docker的第一步,在多种平台上快速安装Docker环境. 它支持多种平台,让用户在很短时间内搭建一套Docker主机集群. M ...

  5. docker三剑客之 Docker Machine Docker Compose Docker Swarm

    Docker 三剑客 一.docker machine 1.Docker Machine 简介 2.Docker Machine实践 二.docker-compose 1.docker-compose ...

  6. Docker(六):Docker 三剑客之 Docker Swarm

    实践中会发现,生产环境中使用单个 Docker 节点是远远不够的,搭建 Docker 集群势在必行.然而,面对 Kubernetes, Mesos 以及 Swarm 等众多容器集群系统,我们该如何选择 ...

  7. Docker三剑客之Docker Swarm

    目录 一.什么是Docker Swarm 二.Docker Swarm 基本结构图 三.Swarm的几个关键概念 四.Swarm的工作模式 五.Swarm的调度策略 六.Swarm Cluster模式 ...

  8. Docker(四):Docker 三剑客之 Docker Compose

    前两篇文章我们介绍了 Dockerfile 的使用Docker(二):Dockerfile 使用介绍,我们知道使用一个 Dockerfile 模板文件可以定义一个单独的应用容器,如果需要定义多个容器就 ...

  9. Docker 三剑客之 Docker Compose

    Docker Compose 项目是 Docker 官方的开源项目,负责实现对 Docker 容器集群的快速编排,开源地址:https://github.com/docker/compose Dock ...

  10. Docker三剑客之Docker compose多容器管理(nginx+haproxy实现负载均衡)

    1.前言 Docker Compose 将所管理的容器分为三层,工程(project),服务(service)以及容器(contaienr) Docker Compose 运行的目录下的所有文件(do ...

最新文章

  1. 一个云服务器可以部署多个项目吗,云服务器可以部署多个项目
  2. 【Android 性能优化】应用启动优化 ( 安卓应用启动分析 | Launcher 应用简介 | Launcher 应用源码简介 | Launcher 应用快捷方式图标点击方法分析 )
  3. ANSYS Products 19.1 安装教程
  4. linux下文件操作
  5. 16 导出pcb各网络的布线长度_PCB原理图常见错误分析
  6. 使用SQLite数据库存储数据(1)-操作SQLite数据库
  7. jQuery使用CDN加速
  8. 在 Asp.Net Core 中使用 worker services
  9. python 列表中dict中key排序
  10. ARM汇编加载/存储指令
  11. 自学编程的八大误区!克服它们,豁然开朗!
  12. sklearn 与 xgboost 的组合使用
  13. hdfs居然无法正常停止
  14. opencv-python学习一--人脸检测
  15. 关于存储pose时.dat类型的文件里面的type问题(细节)
  16. 基于文本数据的情感分析系统
  17. matlab的做潮流计算,Matlab实现潮流计算程序
  18. 中华石杉Java面试突击第一季笔记一(消息队列)
  19. Rockchip | Rockchip Camera技术
  20. 科学家要用3D打印技术复制大脑,今后人类都可以“永生”了

热门文章

  1. 记录x86调试命令总结
  2. resnet50训练imagenet记录
  3. 路径总和 II—leetcode113
  4. 代码执行流水之循环展开优化
  5. UBoot讲解和实践-----------讲解(一)
  6. MySQL的原理以及流程_MySQL的复制原理以及流程?
  7. python 之 linecache 用法记录
  8. xml文档的「?xml version=“1.0“ encoding=“UTF-8“?」 的作用?
  9. 概率论-2.1 随机变量及其分布(重点:右连续的来源)
  10. [攻防世界 pwn]——CGfsb