Docker系列(4):docker-machine

摘要

Windows下启动docker-machine

1
2
docker-machine start
docker-machine env | Invoke-Expression

查看vm主机环境

1
2
3
4
5
6
7
[root@node2 ~]# docker-machine env default
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.100:2376"
export DOCKER_CERT_PATH="/root/.docker/machine/machines/default"
export DOCKER_MACHINE_NAME="default"
# Run this command to configure your shell:
# eval $(docker-machine env default)

管理vm主机

1
[root@node2 ~]# eval $(docker-machine env default)

docker-machine常用命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
docker-machine config
docker-machine env
docker-machine inspect
docker-machine ip #这个命令也能让你知道你当前管理的主机IP
docker-machine kill
docker-machine provision
docker-machine regenerate-certs
docker-machine restart
docker-machine ssh #远程ssh连接到docker虚拟机上
docker-machine start
docker-machine status
docker-machine stop #暂停docker虚拟机
docker-machine upgrade
docker-machine url

Docker-machine源的配置

1
2
3
4
5
6
7
8
#!/bin/bash

# 本脚本用于优化虚拟机的docker镜像源,修改为与localhost一样的中科大源
for NODE in `seq 1 5`
do
docker-machine scp /etc/docker/daemon.json node-${NODE}:/home/docker
docker-machine ssh node-${NODE} 'sudo mv /home/docker/daemon.json /etc/docker/daemon.json && sudo chown root:root /etc/docker/daemon.json && sudo kill -SIGHUP $(pidof dockerd)'
done

参考:

https://www.jianshu.com/p/a40c07f9f456