Docker Machine是一个安装和管理 Docker 的工具, 它有自己的命令行工具:docker-machine。
Docker Machine简化了Docker的安装和远程管理, 不仅可以管理安装本地的docker服务和管理docker容器,也可以管理远程主机上面运行的
docker程序.

主要的执行步骤如下:

1.创建ssh密钥,并传送到远程主机
2.docker-machine 为远程主机安装docker
3.本地登录远程主机并执行命令

docker-machine create --driver generic --generic-ip-address=192.168.11.151 --generic-ssh-key ~/.ssh/id_rsa --generic-ssh-user=lin host1

docker-machine env

1.创建ssh密钥,并传送到远程主机
1.1 创建ssh密钥
root@lin:~# 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:SSLhhgQ7S18RaW2lGn7IB898c+2WqILeDh8eznH81dY root@lin
The key's randomart image is:
+---[RSA 2048]----+
|... .o+ .. |
| o o +.o. |
|o.. =+o.. |
|.o..+.Oo . . |
|. . = *So . . |
| o o o o o .|
| ..+ o . = oE|
| .B.= o o . |
| ...B.. . |
+----[SHA256]-----+

1.2 添加ssh文件到远程主机
root@lin:~# ssh-copy-id -i ~/.ssh/id_rsa.pub lin@192.168.12.151
/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
lin@192.168.12.151's password:

Number of key(s) added: 1

Now try logging into the machine, with: "ssh 'lin@192.168.12.151'"
and check to make sure that only the key(s) you wanted were added.

docker-machine create -d generic --generic-ip-address=192.168.12.151 --generic-ssh-key ~/.ssh/id_rsa --generic-ssh-user=lin host2

2.docker-machine 为远程主机安装docker
root@lin:~# docker-machine create -d generic --generic-ip-address=192.168.12.151 --generic-ssh-key ~/.ssh/id_rsa --generic-ssh-user=lin host1
Running pre-create checks...
Creating machine...
(host1) Importing SSH key...
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

安装日志查看:

3.查看远程主机docker
root@lin:~# docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
host1 - generic Running tcp://192.168.12.151:2376 v17.12.0-ce

4.登录远程主机查看docker信息
root@host1:~# cat /etc/systemd/system/docker.service.d/10-machine.conf
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2376 -H unix:///var/run/docker.sock --storage-driver aufs --tlsverify --tlscacert /etc/docker/ca.pem --tlscert /etc/docker/server.pem --tlskey /etc/docker/server-key.pem --label provider=generic
Environment=
查看docker进程:
root@host1:~# ps aux |grep docker
root 9185 0.0 1.3 495084 53804 ? Ssl 21:33 0:00 /usr/bin/dockerd -H tcp://0.0.0.0:2376 -H unix:///var/run/docker.sock --storage-driver aufs --tlsverify --tlscacert /etc/docker/ca.pem --tlscert /etc/docker/server.pem --tlskey /etc/docker/server-key.pem --label provider=generic
root 9204 0.0 0.6 225496 25516 ? Ssl 21:33 0:00 docker-containerd --config /var/run/docker/containerd/containerd.toml
root 9788 0.0 0.0 21292 948 pts/17 S+ 21:39 0:00 grep --color=auto docker
root@host1:~#
-H tcp://0.0.0.0:2376 使 docker daemon 接受远程连接。
--tls* 对远程连接启用安全认证和加密。
远程主机名称被修改:
root@host1:~# hostname
host1

本地主机启动远程主机docker:
[root@lin ~]# docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
host1 - generic Running tcp://192.168.12.151:2376 v17.12.0-ce

[root@lin ~]# eval $(docker-machine env host1)

[root@lin ~ [host1]]# docker run -itd busybox
Unable to find image 'busybox:latest' locally
latest: Pulling from library/busybox
0ffadd58f2a6: Pull complete
Digest: sha256:bbc3a03235220b170ba48a157dd097dd1379299370e1ed99ce976df0355d24f0
Status: Downloaded newer image for busybox:latest
8c0414aa5b4e27185ee8949034dd120e3df5c7d6a51112d4a71b1787f1472c78
[root@lin ~ [host1]]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8c0414aa5b4e busybox "sh" 47 seconds ago Up 46 seconds kind_joliot

远程主机查看:
root@host1:~# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8c0414aa5b4e busybox "sh" 14 seconds ago Up 13 seconds kind_joliot

启动另外一个docker主机:
[root@lin ~ [host1]]# docker-machine create -d generic --generic-ip-address=192.168.12.196 --generic-ssh-key ~/.ssh/id_rsa --generic-ssh-user=lin host3
Running pre-create checks...
Creating machine...
(host2) Importing SSH key...
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 host3
[root@lin ~ [host1]]# eval $(docker-machine env host2)
[[root@lin ~ [host2]]# docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
host1 * generic Running tcp://192.168.12.151:2376 v17.12.0-ce
host3 - generic Running tcp://192.168.12.196:2376 v17.12.0-ce

其他docker-machine命令:
docker-machine upgrade 更新 machine 的 docker 到最新版本,可以批量执行
[root@lin ~]# docker-machine upgrade host1
Waiting for SSH to be available...
Detecting the provisioner...
Upgrading docker...
Restarting docker...
docker-machine config 查看 machine 的 docker daemon 配置:
[root@lin ~]# docker-machine config host1
--tlsverify
--tlscacert="/root/.docker/machine/machines/host1/ca.pem"
--tlscert="/root/.docker/machine/machines/host1/cert.pem"
--tlskey="/root/.docker/machine/machines/host1/key.pem"
-H=tcp://192.168.12.151:2376

stop/start/restart 是对 machine 的操作系统操作,而 不是 stop/start/restart docker daemon。
docker-machine scp 可以在不同 machine 之间拷贝文件,比如:
docker-machine scp host1:/tmp/a host2:/tmp/b

获取远程主机URL,并在主机上执行命令:
[root@lin ~ [host3]]# docker-machine url host1
tcp://192.168.12.151:2376
[root@lin ~ [host3]]# docker -H tcp://192.168.12.151:2376 ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

其他命令:
Commands:
active Print which machine is active
config Print the connection config for machine
create Create a machine
env Display the commands to set up the environment for the Docker client
inspect Inspect information about a machine
ip Get the IP address of a machine
kill Kill a machine
ls List machines
provision Re-provision existing machines
regenerate-certs Regenerate TLS Certificates for a machine
restart Restart a machine
rm Remove a machine
ssh Log into or run a command on a machine with SSH.
scp Copy files between machines
mount Mount or unmount a directory from a machine with SSHFS.
start Start a machine
status Get the status of a machine
stop Stop a machine
upgrade Upgrade a machine to the latest version of Docker
url Get the URL of a machine
version Show the Docker Machine version or a machine docker version

dcoker machine的更多相关文章

  1. Docker学习—Machine

    前言 前面<Docker学习-Compose>文中介绍了Compose的使用方式:接下来继续了解docker三剑客之一的 Machine: 一.Docker Machine简介 1.什么是 ...

  2. 【Machine Learning】KNN算法虹膜图片识别

    K-近邻算法虹膜图片识别实战 作者:白宁超 2017年1月3日18:26:33 摘要:随着机器学习和深度学习的热潮,各种图书层出不穷.然而多数是基础理论知识介绍,缺乏实现的深入理解.本系列文章是作者结 ...

  3. 【Machine Learning】Python开发工具:Anaconda+Sublime

    Python开发工具:Anaconda+Sublime 作者:白宁超 2016年12月23日21:24:51 摘要:随着机器学习和深度学习的热潮,各种图书层出不穷.然而多数是基础理论知识介绍,缺乏实现 ...

  4. 【Machine Learning】机器学习及其基础概念简介

    机器学习及其基础概念简介 作者:白宁超 2016年12月23日21:24:51 摘要:随着机器学习和深度学习的热潮,各种图书层出不穷.然而多数是基础理论知识介绍,缺乏实现的深入理解.本系列文章是作者结 ...

  5. 【Machine Learning】决策树案例:基于python的商品购买能力预测系统

    决策树在商品购买能力预测案例中的算法实现 作者:白宁超 2016年12月24日22:05:42 摘要:随着机器学习和深度学习的热潮,各种图书层出不穷.然而多数是基础理论知识介绍,缺乏实现的深入理解.本 ...

  6. 【机器学习Machine Learning】资料大全

    昨天总结了深度学习的资料,今天把机器学习的资料也总结一下(友情提示:有些网站需要"科学上网"^_^) 推荐几本好书: 1.Pattern Recognition and Machi ...

  7. [Machine Learning] Active Learning

    1. 写在前面 在机器学习(Machine learning)领域,监督学习(Supervised learning).非监督学习(Unsupervised learning)以及半监督学习(Semi ...

  8. [Machine Learning & Algorithm]CAML机器学习系列2:深入浅出ML之Entropy-Based家族

    声明:本博客整理自博友@zhouyong计算广告与机器学习-技术共享平台,尊重原创,欢迎感兴趣的博友查看原文. 写在前面 记得在<Pattern Recognition And Machine ...

  9. CPU acceleration status: HAXM is not installed on this machine解决方法

    报错信息: Starting emulator for AVD 'old_android' emulator: WARNING: Classic qemu does not support SMP. ...

随机推荐

  1. python之连接oracle数据库

    环境: windows,python2.7 1.下载cx_Oracle 在windows下不要使用easy_install或者pip,因为这样安装不会同步环境,并报错: distutils.error ...

  2. 奇妙的 Storage::url

    发现 这是我在做头像上传功能时发现的,下面是图片上传的业务逻辑. class AvatarController extends Controller { public function update( ...

  3. 使用Sqlserver事务发布实现数据同步(转)

    出处:http://www.cnblogs.com/daizhj/archive/2009/11/18/1605293.html 事务的功能在sqlserver中由来已久,因为最近在做一个数据同步方案 ...

  4. 企业管理系统——第三周需求&原型改进_张正浩,黄锐斌

    企业管理系统——需求&原型改进,架构设计,测试计划 组员:张正浩,黄锐斌 一.需求&原型改进 1.给目标用户展现原型,与目标用户进一步沟通理解需求 我们的目标用户是公司管理员 场景:随 ...

  5. Android内置和外置SD卡的位置获取

    public class StorageUtils { private static String TAG="123"; // 获取主存储卡路径 内置内存卡路径 public st ...

  6. owinAuthorize

    Nuget包获取 Install-Package Microsoft.AspNet.WebApi.Owin -Version 5.1.2 Install-Package Microsoft.Owin. ...

  7. MVC 路由调试工具-RouteDebugger

    MVC  路由调试工具-RouteDebugger 方案一: 在程序包控制台中执行命令 PM> Install-Package routedebugger 自动会在你的项目webconfig中& ...

  8. 【大数据之数据仓库】安装部署GreenPlum集群

    本篇将向大家介绍如何快捷的安装部署GreenPlum测试集群,大家可以跟着我一块儿实践一把^_^ 1.主机资源 申请2台网易云主机,操作系统必须是RedHat或者CentOS,配置尽量高一点.如果是s ...

  9. 201621123012 《Java程序设计》第1周学习总结

    1. 本章学习总结 学习了java的理论知识和它与C语言的差别,什么是JVM,区分JRE与JDK并学习JAVA环境的安装.熟悉控制台下的常用命令,java函数的编写.熟练使用编写JAVA所需要的工具( ...

  10. Mysql初识数据库《五》初识sql语句

    初识sql语句 有了mysql这个数据库软件,就可以将程序员从对数据的管理中解脱出来,专注于对程序逻辑的编写 mysql服务端软件即mysqld帮我们管理好文件夹以及文件,前提是作为使用者的我们,需要 ...