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. WEB前端--CSS

    一.认识CSS 1.概念 CSS(Cascading Style Sheet,层叠样式表),可以将网页制作的更加绚丽多彩.它可以有效的对页面的布局.字体.颜色.背景和其它效果实现更加精确的控制. 2. ...

  2. laravel中的attach and detach toggle method

    创建模型 post  and  user 以及 users , posts ,user_post(favorities)测试数据 在此可以看上一篇中的数据,本次测试数据利用的上一篇的数据.detach ...

  3. linq to object 未完待续

    1.linq to string string s2 = "abc"; var data2 = s2.Where(x => x.CompareTo('a') > 0). ...

  4. App测试从入门到精通之App分类和场景操作系统

    App概要 APP是application的缩写.通常指的是手机软件上的应用,或称为手机客户端.手机app就是手机的应用程序.随着智能手机的越发普及,用户越发依赖手机软件商品店,app开发的需求与发展 ...

  5. 进程间传递文件描述符fd

    众所周知,子进程会继承父进程已经打开的文件描述符fd,但是fork之后的是不会被继承的,这个时候是否无能无力了?答应是NO.Linux提供了一个系统调用sendmsg,借助它,可以实现进程间传递文件描 ...

  6. HTML5+CSS3从入门到精通随书光盘 ISO 镜像视频教程​

    HTML5+CSS3从入门到精通(清华社“视频大讲堂”大系)通过基础知识+中小实例+综合案例的方式,讲述了用HTML5+ CSS3设计构建网站的必备知识,相对于权威指南.高级程序设计.开发指南同类图书 ...

  7. webform Response的一些成员

    1. Response.BufferOutPut,关闭缓冲区. 2. Response.Flush,一次性把缓冲区的内容释放出来. 3. Response.Clear,清空缓冲区. 4. Respon ...

  8. Abp使用不同仓储连接多个数据库

    有群友说官方例子中有,无奈英文和网速太差...自己琢磨吧. 最近开发的项目中,需要从外部系统中读取一些信息,计算之后存入本地的数据库中,外部系统直接提供数据库给我..所以本地需要用到多数据库连接. 项 ...

  9. C#中base的作用

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...

  10. 使用Linq读取资源文件

    ResXResourceReader resxr = new ResXResourceReader(txt_WebResourceOpenFile.Text); IEnumerable<Dict ...