docker三剑客之docker-machine

#安装docker-machine
[email protected]:~$ pwd
/home/cupid
[email protected]:~$ ls
Desktop  docker-machine-Linux-x86_64  Documents  Downloads  examples.desktop  Music  Pictures  Public  Templates  Videos
[email protected]:~$ mv docker-machine-Linux-x86_64  docker-machine
[email protected]:~$ chmod +x  docker-machine
[email protected]:~$ sudo scp docker-machine /usr/local/bin/docker-machine
[email protected]:~$ docker-machine  version  #安装成功
docker-machine version 0.12.2, build 9371605
##
[email protected]:~$ cd /etc/bash_completion.d/
[email protected]:/etc/bash_completion.d$ ls
apport_completion      git-prompt  insserv
desktop-file-validate  grub        libreoffice.sh
[email protected]:/etc/bash_completion.d$ vi docker-machine-prompt.bash
~
##添加被管理节点
1)生成ssh-key并拷贝到被管理节点
[email protected]:~# 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 [email protected]
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]-----+
[email protected]:~# 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
[email protected]‘s password: 

Number of key(s) added: 1

Now 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.

[email protected]:~# 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
[email protected]‘s password: 

Number of key(s) added: 1

Now 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
[email protected]:~# 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/advantage

52 packages can be updated.
1 update is a security update.
2)添加被管理节点 因为是虚拟机,指定普通操作系统即可
[email protected]:~# 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
#查看添加的主机
[email protected]:~# 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
[[email protected]:~]#echo $PS1
[\[email protected]\h:\w$(__docker_machine_ps1)]\$
[[email protected]:~]#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需要的环境变量
[[email protected]:~]#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需要的环境变量
[[email protected]:~]#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
[[email protected]:~]#eval $(docker-machine env host2)

[[email protected]:~ [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
~
时间: 2024-10-12 22:33:10

docker三剑客之docker-machine的相关文章

docker——三剑客之Docker Machine

Docker Machine是Docker官方三剑客项目之一,负责使用Docker的第一步,在多种平台上快速安装Docker环境.它支持多种平台,让用户在很短时间内搭建一套Docker主机集群. Machine项目是Docker官方的开源项目,负责实现对Docker主机本身进行管理.Machine项目主要由GO编写,用户可以在本地任意指定被Machine管理的Docker主机,并对其进行操作.Machine定位是"在本地或者云环境中创建Docker主机" Docker Machine是

docker三剑客之应用machine,compose,swarm

利用Docker-Machine创建虚拟Docker主机 ## 下载docker-machine https://github.com/docker/machine/releases [email protected]:~$ curl -L https://github.com/docker/machine/releases/download/v0.16.0/docker-machine-`uname -s`-`uname -m` >/tmp/docker-machine && ch

docker——三剑客之Docker swarm

Docker Swarm是Docker官方的三剑客项目之一,提供Docker容器集群服务,是Docker官方对容器云生态进行支持的核心方案.使用它,用户可以将多个Docker主机封装为单个大型的虚拟Docker主机,快速打造一套容器云平台. Docker Swarm是Docker公司推出的官方容器集群平台,基于Go语言实现.目前,包括Rackspace在内的许多平台都采用了Swarm,用户很容易在AWS等公有云平台使用Swarm. Swarm的前身是Beam项目和libswarm项目,首个正式版

Docker 三剑客之Docker Swarm

Docker Swarm 介绍 创建Docker Swarm集群 1.使用docker machine ssh连接到想要成为manager node的那台docker宿主机上. $ docker-machine ssh manager1 2.执行下面的命令,创建一个swarm集群. docker swarm init --advertise-addr <MANAGER-IP> 例如: # docker swarm init --advertise-addr 43.241.208.252 Swa

docker三剑客之docker compose

compose环境变量 以DOCKER_开头的变量和用来配置Docker命令行客户端的使用一样,如果使用boot2docker,${boot2dockershellinit}将会设置他们为正确的值 compose环境变量: COMPOSE_PROJECT_NAME: 设置compose的项目名称,默认是当前工作目录(docker-compose.yml文件所在目录)的名字 compose会为每一个启动的容器前添加项目名称.例如一个名称为proj的项目,其中的一个web容器,名称可能为proj_w

docker三剑客之一docker compose

compose有两个重要的概念: 服务(service):一个应用的容器,实际上可以包括若干运行相同镜像的容器实例 项目(project):由一组关联的应用容器组成的一个完整业务单元,在docker-compose.yml文件中定义 compose默认管理对象是项目,通过子命令对项目中的一组容器进行便捷地生命周期管理 安装 pip安装,下载编译好的二进制文件,直接运行在docker容器中三种方案: pip安装: apt-get install python-pip -y pip install

docker三剑客之docker swarm

Swarm是什么 Swarm这个项目名称特别贴切.在Wiki的解释中,Swarm behavior是指动物的群集行为.比如我们常见的蜂群,鱼群,秋天往南飞的雁群都可以称作Swarm behavior. 安装 1.下载镜像 docker pull swarm docker run --rm swarm -v 2.配置节点 docker主机在加入swarm集群前,要进行配置,添加docker daemon的网络监听,例如,在启动docker daemon的时候通过-H参数: sudo docker

docker——三剑客之Docker Compose

编排(Orchestration)功能是复杂系统实现灵活可操作性的关键.特别是在Docker应用场景中,编排意味着用户可以灵活的对各种容器资源实现定义和管理. 作为Docker官方编排工具,Compose的重要性不言而喻,它可以让用户通过编写一个简单模板文件,快速地创建和管理基于Docker容器地应用集群. Compose项目是Docker官方的开源项目,负责实现对Docker容器的快速编排.从功能上看,跟OpenStack中的Heat十分相似.Compose定位是"定义和运行多个Docker容

Docker三剑客之Machine

前言 Docker Machine 是 Docker 官方编排(Orchestration)项目之一,负责在多种平台上快速安装 Docker 环境. Docker Machine 项目基于 Go 语言实现,目前在 Github 上进行维护. 安装 原文地址:https://www.cnblogs.com/guge-94/p/11102076.html

Docker三剑客之Swarm介绍

DockOne技术分享(二十): 我用swarm在多台物理机调度管理容器,用ovs实现跨主机的容器互联问题 [编者的话]Swarm项目是Docker公司发布三剑客中的一员,用来提供容器集群服务,目的是更好的帮助用户管理多个Docker Engine,方便用户使用,像使用Docker Engine一样使用容器集群服务.这次分享内容从Swarm项目现状.Swarm社区现状和Swarm未来的一些规划三方面介绍Swarm,目的是能让大家对Swarm有个完整的认识,并且希望更多的人采用到Swarm项目中来