喵♂呜 的博客

一个刚毕业就当爹的程序猿 正在迷雾中寻找道路...

DockerMachine的安装与使用

DockerMachine用于管理多台机器上的DockerDaemon

安装

1
wget -qO- https://blog.yumc.pw/attachment/script/shell/docker/machine.sh | bash

创建/添加

注意: 首先要保证管理主机和各台机器之间能够SSH直连互通 同时打开Docker的管理端口

  • 防火墙开启
1
2
3
4
5
6
firewall-cmd --zone=public --add-port=2376/tcp --permanent
firewall-cmd --zone=public --add-port=2377/tcp --permanent
firewall-cmd --zone=public --add-port=7946/tcp --permanent
firewall-cmd --zone=public --add-port=7946/udp --permanent
firewall-cmd --zone=public --add-port=4789/udp --permanent
firewall-cmd --reload

添加实体机器

  • 执行 docker-machine create --driver generic --generic-ip-address=<服务器地址> <名称>
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    [root@207 ~]# docker-machine create --driver generic --generic-ip-address=192.168.2.208 208
    Running pre-create checks...
    Creating machine...
    (208) 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 centos...
    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 208

使用/命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
[root@2-225 ~]# docker-machine                                                                                                                       
Usage: docker-machine [OPTIONS] COMMAND [arg...]

Create and manage machines running Docker.

Version: 0.15.0, build b48dc28d

Author:
Docker Machine Contributors - <https://github.com/docker/machine>

Options:
--debug, -D 开启调试模式
--storage-path, -s "/root/.docker/machine" Configures storage path [$MACHINE_STORAGE_PATH]
--tls-ca-cert CA to verify remotes against [$MACHINE_TLS_CA_CERT]
--tls-ca-key Private key to generate certificates [$MACHINE_TLS_CA_KEY]
--tls-client-cert Client cert to use for TLS [$MACHINE_TLS_CLIENT_CERT]
--tls-client-key Private key used in client TLS auth [$MACHINE_TLS_CLIENT_KEY]
--github-api-token Token to use for requests to the Github API [$MACHINE_GITHUB_API_TOKEN]
--native-ssh Use the native (Go-based) SSH implementation. [$MACHINE_NATIVE_SSH]
--bugsnag-api-token BugSnag API token for crash reporting [$MACHINE_BUGSNAG_API_TOKEN]
--help, -h show help
--version, -v print the version

Commands:
active 打印已激活的机器
config 打印机器的详细信息
create 创建一个机器
env Display the commands to set up the environment for the Docker client
inspect Inspect information about a machine
ip 获得机器的IP
kill Kill a machine
ls List machines
provision Re-provision existing machines
regenerate-certs Regenerate TLS Certificates for a machine
restart 重启一个机器
rm 移除一个机器
ssh 通过SSH登录机器并且执行命令.
scp 在两个机器之间复制文件
mount 使用SSHFS挂载目录.
start 启动一个机器
status Get the status of a machine
stop 停止一个机器
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
help Shows a list of commands or help for one command

Run 'docker-machine COMMAND --help' for more information on a command.

欢迎关注我的其它发布渠道