概述
安装
使用docker-machine来创建virtualbox虚拟机
~ docker-machine env bboysoul
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.100:2376"
export DOCKER_CERT_PATH="/home/bboysoul/.docker/machine/machines/bboysoul"
export DOCKER_MACHINE_NAME="bboysoul"
# Run this command to configure your shell:
# eval $(docker-machine env bboysoul)复制代码
~ docker-machine ssh bboysoul
## .
## ## ## ==
## ## ## ## ## ===
/"""""""""""""""""\___/ ===
~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ / ===- ~~~
\______ o __/
\ \ __/
\____\_______/
_ _ ____ _ _
| |__ ___ ___ | |_|___ \ __| | ___ ___| | _____ _ __
| '_ \ / _ \ / _ \| __| __) / _` |/ _ \ / __| |/ / _ \ '__|
| |_) | (_) | (_) | |_ / __/ (_| | (_) | (__| < __/ |
|_.__/ \___/ \___/ \__|_____\__,_|\___/ \___|_|\_\___|_|
Boot2Docker version 18.01.0-ce, build HEAD : 0bb7bbd - Thu Jan 11 16:32:39 UTC 2018
Docker version 18.01.0-ce, build 03596f5
docker@bboysoul:~$ 复制代码
docker-machine create -d virtualbox \
--virtualbox-disk-size 30000 \
--virtualbox-cpu-count 2 \
--virtualbox-memory 2048 \
bboysoul2复制代码
对了,我没有解释-d
的意思-d
就是驱动,为什么叫驱动呢,因为它的英文叫drive,所以就翻译成驱动了,但是我总觉得叫驱动不好,会误人子弟。官方支持的驱动有下面这些
- amazonec2
- azure
- digitalocean
- exoscale
- generic
- hyperv
- none
- openstack
- rackspace
- softlayer
- virtualbox
- vmwarevcloudair
- vmwarefusion
- vmwarevsphere
让docker-machine和阿里云搞cp
我发现网上,包括阿里云有的东西不全面,找了很久,我现在把阿里云docker-machine驱动的参数解释一下
export ECS_ACCESS_KEY_ID='<Your access key ID>'
export ECS_ACCESS_KEY_SECRET='<Your secret access key>'复制代码
export ECS_ACCESS_KEY_ID=''
export ECS_ACCESS_KEY_SECRET=''
export ECS_INSTANCE_TYPE='ecs.t5-lc2m1.nano'
export ECS_INTERNET_MAX_BANDWIDTH='1'
export ECS_REGION='cn-shanghai'
export ECS_SSH_PASSWORD='Lovexiu520'
export ECS_SYSTEM_DISK_SIZE='40'
export ECS_SYSTEM_DISK_CATEGORY='cloud_efficiency'
export ECS_IMAGE_ID='coreos_1465_8_0_64_30G_alibase_20171024.vhd'
export ECS_VPC_ID='vpc-uf69wb7af3njhw9bbnqk8'
export ECS_VSWITCH_ID='vsw-uf6u8cpl0ulbhbg5fbkv4'
export ECS_TAGS='bboysoul_docker'
export ECS_SECURITY_GROUP='sg-uf61dkll1qn5gsgr1ekq'
export ECS_ZONE='cn-shanghai-d'
export ECS_IO_OPTIMIZED='true'复制代码
保存成文件然后用source命令导入环境变量source ./bboysoul
接着开启虚拟机 docker-machine create -d aliyunecs <machine-name>
temp docker-machine create -d aliyunecs bboysoul
Running pre-create checks...
Creating machine...
(bboysoul) bboysoul | Creating key pair for instance ...
(bboysoul) bboysoul | Configuring security groups instance ...
(bboysoul) bboysoul | Creating instance with image coreos_1465_8_0_64_30G_alibase_20171024.vhd ...
(bboysoul) bboysoul | Create instance i-uf6e3icwjtndmsao0fhi successfully
(bboysoul) bboysoul | Allocating Eip address for instance i-uf6e3icwjtndmsao0fhi ...
(bboysoul) bboysoul | Associating Eip address eip-uf6pzzvr03ejx5v9h24rq for instance i-uf6e3icwjtndmsao0fhi ...
(bboysoul) bboysoul | Starting instance i-uf6e3icwjtndmsao0fhi ...
(bboysoul) bboysoul | Start instance i-uf6e3icwjtndmsao0fhi successfully
(bboysoul) bboysoul | Waiting SSH service 106.14.0.160:22 is ready to connect ...
(bboysoul) bboysoul | Uploading SSH keypair to 106.14.0.160:22 ...
(bboysoul) bboysoul | Created instance i-uf6e3icwjtndmsao0fhi successfully with public IP address 106.14.0.160 and private IP address 192.168.1.207
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 coreOS...
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 bboysoul复制代码
接着执行docker-machine ssh bboysoul
没错,可以进来
temp docker-machine ssh bboysoul
Last login: Tue Jan 30 00:10:38 CST 2018 from 115.215.201.25 on ssh
Welcome to Alibaba Cloud Elastic Compute Service !
bboysoul ~ # 复制代码
docker-machine create -d aliyunecs \
--aliyunecs-access-key-id='' \
--aliyunecs-access-key-secret='' \
--aliyunecs-system-disk-size='40' \
--aliyunecs-system-disk-category='cloud_efficiency' \
--aliyunecs-image-id='coreos_1465_8_0_64_30G_alibase_20171024.vhd' \
--aliyunecs-io-optimized='true' \
--aliyunecs-instance-type='ecs.t5-lc2m1.nano' \
--aliyunecs-internet-max-bandwidth='1' \
--aliyunecs-region='cn-shanghai' \
--aliyunecs-security-group='sg-uf61dkll1qn5gsgr1ekq' \
--aliyunecs-ssh-password='Lovexiu520' \
--aliyunecs-tag bboysoul=docker \
--aliyunecs-vpc-id='vpc-uf69wb7af3njhw9bbnqk8' \
--aliyunecs-vswitch-id='vsw-uf6u8cpl0ulbhbg5fbkv4' \
--aliyunecs-zone='cn-shanghai-d' \
bboysoul复制代码
~ docker-machine create -d aliyunecs \
--aliyunecs-access-key-id='' \
--aliyunecs-access-key-secret='' \
--aliyunecs-system-disk-size='40' \
--aliyunecs-system-disk-category='cloud_efficiency' \
--aliyunecs-image-id='coreos_1465_8_0_64_30G_alibase_20171024.vhd' \
--aliyunecs-io-optimized='true' \
--aliyunecs-instance-type='ecs.t5-lc2m1.nano' \
--aliyunecs-internet-max-bandwidth='1' \
--aliyunecs-region='cn-shanghai' \
--aliyunecs-security-group='sg-uf61dkll1qn5gsgr1ekq' \
--aliyunecs-ssh-password='Lovexiu520' \
--aliyunecs-tag bboysoul=docker \
--aliyunecs-vpc-id='vpc-uf69wb7af3njhw9bbnqk8' \
--aliyunecs-vswitch-id='vsw-uf6u8cpl0ulbhbg5fbkv4' \
--aliyunecs-zone='cn-shanghai-d' \
bboysoul
Running pre-create checks...
Creating machine...
(bboysoul) bboysoul | Creating key pair for instance ...
(bboysoul) bboysoul | Configuring security groups instance ...
(bboysoul) bboysoul | Creating instance with image coreos_1465_8_0_64_30G_alibase_20171024.vhd ...
(bboysoul) bboysoul | Create instance i-uf68n9kyxczoz4iadkjw successfully
(bboysoul) bboysoul | Allocating Eip address for instance i-uf68n9kyxczoz4iadkjw ...
(bboysoul) bboysoul | Associating Eip address eip-uf6duc6fbs0x6vh392qgh for instance i-uf68n9kyxczoz4iadkjw ...
(bboysoul) bboysoul | Starting instance i-uf68n9kyxczoz4iadkjw ...
(bboysoul) bboysoul | Start instance i-uf68n9kyxczoz4iadkjw successfully
(bboysoul) bboysoul | Waiting SSH service 106.14.224.72:22 is ready to connect ...
(bboysoul) bboysoul | Uploading SSH keypair to 106.14.224.72:22 ...
(bboysoul) bboysoul | Created instance i-uf68n9kyxczoz4iadkjw successfully with public IP address 106.14.224.72 and private IP address 192.168.1.209
(bboysoul) bboysoul | Adding tags map[bboysoul:docker] to instance i-uf68n9kyxczoz4iadkjw ...
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 coreOS...
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 bboysoul复制代码
~ docker-machine ssh bboysoul
Last login: Tue Jan 30 00:42:28 CST 2018 from 115.215.201.25 on ssh
Welcome to Alibaba Cloud Elastic Compute Service !
bboysoul ~ # 复制代码
docker-machine 常用命令
最后说一下常用命令把,其实也没什么好讲的,都在help里面有,下面都是docker-machine后加的命令就是docker-machine command
- active 查看活跃的 Docker 主机
- config 输出连接的配置信息
- create 创建一个 Docker 主机
- env 显示连接到某个主机需要的环境变量
- inspect 输出主机更多信息
- ip 获取主机地址
- kill 停止某个主机
- ls 列出所有管理的主机
- provision 重新设置一个已存在的主机
- regenerate-certs 为某个主机重新生成 TLS 认证信息
- restart 重启主机
- rm 删除某台主机
- ssh SSH 到主机上执行命令
- scp 在主机之间复制文件
- mount 挂载主机目录到本地
- start 启动一个主机
- status 查看主机状态
- stop 停止一个主机
- upgrade 更新主机 Docker 版本为最新
- url 获取主机的 URL
- version 输出 docker-machine 版本信息
- help 输出帮助信息