dcoker machine
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的更多相关文章
- Docker学习—Machine
前言 前面<Docker学习-Compose>文中介绍了Compose的使用方式:接下来继续了解docker三剑客之一的 Machine: 一.Docker Machine简介 1.什么是 ...
- 【Machine Learning】KNN算法虹膜图片识别
K-近邻算法虹膜图片识别实战 作者:白宁超 2017年1月3日18:26:33 摘要:随着机器学习和深度学习的热潮,各种图书层出不穷.然而多数是基础理论知识介绍,缺乏实现的深入理解.本系列文章是作者结 ...
- 【Machine Learning】Python开发工具:Anaconda+Sublime
Python开发工具:Anaconda+Sublime 作者:白宁超 2016年12月23日21:24:51 摘要:随着机器学习和深度学习的热潮,各种图书层出不穷.然而多数是基础理论知识介绍,缺乏实现 ...
- 【Machine Learning】机器学习及其基础概念简介
机器学习及其基础概念简介 作者:白宁超 2016年12月23日21:24:51 摘要:随着机器学习和深度学习的热潮,各种图书层出不穷.然而多数是基础理论知识介绍,缺乏实现的深入理解.本系列文章是作者结 ...
- 【Machine Learning】决策树案例:基于python的商品购买能力预测系统
决策树在商品购买能力预测案例中的算法实现 作者:白宁超 2016年12月24日22:05:42 摘要:随着机器学习和深度学习的热潮,各种图书层出不穷.然而多数是基础理论知识介绍,缺乏实现的深入理解.本 ...
- 【机器学习Machine Learning】资料大全
昨天总结了深度学习的资料,今天把机器学习的资料也总结一下(友情提示:有些网站需要"科学上网"^_^) 推荐几本好书: 1.Pattern Recognition and Machi ...
- [Machine Learning] Active Learning
1. 写在前面 在机器学习(Machine learning)领域,监督学习(Supervised learning).非监督学习(Unsupervised learning)以及半监督学习(Semi ...
- [Machine Learning & Algorithm]CAML机器学习系列2:深入浅出ML之Entropy-Based家族
声明:本博客整理自博友@zhouyong计算广告与机器学习-技术共享平台,尊重原创,欢迎感兴趣的博友查看原文. 写在前面 记得在<Pattern Recognition And Machine ...
- CPU acceleration status: HAXM is not installed on this machine解决方法
报错信息: Starting emulator for AVD 'old_android' emulator: WARNING: Classic qemu does not support SMP. ...
随机推荐
- 认识Filter
1). Filter 是什么 ? ①. JavaWEB 的一个重要组件, 可以对发送到 Servlet 的请求进行拦截, 并对响应也进行拦截. ②. Filter 是实现了 Filter 接口的 Ja ...
- 理解 RESTful WebService
RESTful 服务遵循REST(Representational State Transfer)的架构风格,中文翻译为:表现层状态转化 对于所有的CRUD(Read/Create/Update/De ...
- 构建使用 Azure 网站的云
Apurva JoshiSunitha Muthukrishna 在设计云解决方案时,设计始终要为故障做好准备.这一点很重要,应牢记. 然而,许多应用程序并非按照这种方式构建. 出现这种情况的主要原因 ...
- Linq学习<三> linq to entity
之前一直用sql选择出数据放在一个集合中,然后再用Linq或者lambda去操作数据,今天学了Linq to entity 才知道原来linq产生是为了Entity.也就是EDM(实体数据模型) 关于 ...
- .Net高级面试宝典
1.in/exists/join 执行效率? 答:用法 select * from HK_UsersBasic where Users_ID in (select AccEmail from dbo ...
- web api 设置允许跨域,并设置预检请求时间
<httpProtocol> <customHeaders> <!--响应类型 (值为逗号分隔的一个字符串,表明服务器支持的所有跨域请求的方法)--> <ad ...
- The method identifyUser(Arrays.asList("group001"), String, new HashMap<>()) is undefined for the type AipFace
在使用百度云的人脸识别sdk时遇到了这个错误,网上百度不到解决的方法,当我浏览百度云的时候发现了这个 于是考虑到版本可能更新,出现了新的函数代替旧的函数,于是去查文档,文档链接如下 https://c ...
- 原生态js,返回至顶部
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- MVC,MVP 和 MVVM 的区别之处
其实我一直以来,虽然做的是前端的工作,但是有一个疑问,就是什么是mvc模式,虽然大概知道,但是具体确实说不上来的的,今天,我就好好总结一下mvc ,mvp,mvvm模式的区别与相同. 1.MVC模式: ...
- ceph_osd故障检测
1. 当前monitor可以通过3种途径检测到osd离线 1) Osd自主上报 2) Osd通过投票的方式(满足一下条件之一,mon会将osd标记为down) a) ...