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. Struts中ActionContext和ServletActionContext的比较

    一.ActionContext在Struts2开发中除了将请求参数自动设置到Action的字段中,往往也需要在Action里直接获取请求(Request)或会话(Session)的一些信息,甚至需要直 ...

  2. cbv+resful+APIView源码分析

    CBV源码分析 1概念:什么是cbv和fbv 已经什么是API class bass View ---基于类的视图 function bass View ---基于函数的视图 API(Applicat ...

  3. 列表推导式对比For循环执行效率

    我们在前面的学习中都知道,如果把1-10以内的元素追加到一个新的列表表中,如果使用for循环我们可以这么做: a = [] for i in range(1,11): a.append(i) prin ...

  4. Oracle数据库之单表查询

    接着上一篇的分享,今天主要给大家分享的是关于数据中的单表查询,单表查询很基础,也很重要,但是任何一个初学者必须要掌握的姿势,单表查询就是对单个表进行操作,查询我们想要的数据.单表查询里面的内容也是比较 ...

  5. [Lua快速了解一下]Lua的语法

    -注释 -- 两个减号是行注释 -块注释 --[[ 这是块注释 这是块注释 --]] -变量 Lua的数字只有double型,64bits, Lua的字符串string支持双引号或者单引号 以下例子会 ...

  6. [转]sessionStorage()和localStorage()的用法

    JS的本地保存localStorage.sessionStorage用法总结: 1. localStorage.sessionStorage是Html5的特性,IE7以下浏览器不支持 为什么要掌握lo ...

  7. android library使用方法

    一.Android library使用情景 通用模块的重复使用,项目做多了,其实都是差不多,核心模块基本无需大的改动,需要改的只是核心模块上的业务功能而已. Java中可以打包成库,或者说,单纯的ja ...

  8. Xshell显示本地数据排版错乱

    解决办法 文件 - 属性 - 终端 - 高级 - 用CR-LF接受LF(R)

  9. 【转】C#工程连接oracle的一种方式

    源地址:https://blog.csdn.net/qq_16542775/article/details/52689068 项目中有个功能需要从一台Oracle数据库获取数据,本以为是很简单的事情, ...

  10. bzoj2115(线性基)

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2115 题意:求图中路径1~n上最大边权 xor 和 思路:参见 blog http://b ...