实现目标
- 使用docker-machine在远程主机安装docker-ce(17.03.2)
- 使用docker-machine登录并管理远程主机的docker
准备环境
- 时间:2019年4月23日
- 本地主机
mint18
- 远程主机
ubuntu16.04
安装docker-machine
配置环境
-
配置ssh登录远程设备
追加本地主机的~/.ssh/id_rsa.pub
到远程主机的~/.ssh/authorized_key
中 -
在远程主机上配置登录用户NOPASSWD权限
创建docker
在本地主机执行命令如下命令
docker-machine create -d generic --generic-ip-address=10.10.11.137 --generic-ssh-user=micro --generic-ssh-key ~/.ssh/id_rsa --engine-install-url="https://raw.githubusercontent.com/rancher/install-docker/master/17.03.2.sh" micro
-d generic
驱动类型--generic-ip-address 10.10.11.137
远程主机ip--generic-ssh-user=micro
ssh用户名--generic-ssh-key ~/.ssh/id_rsa
ssh使用的本地验证文件--engine-install-url="https://raw.githubusercontent.com/rancher/install-docker/master/17.03.2.sh"
17.03.2docker安装脚本
gws@gws-TP450:~$ docker-machine create -d generic --generic-ip-address=10.10.11.137 --generic-ssh-user=micro --generic-ssh-key ~/.ssh/id_rsa --engine-install-url="https://raw.githubusercontent.com/rancher/install-docker/master/17.03.2.sh" micro
Running pre-create checks...
Creating machine...
(micro) 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 micro
查看
gws@gws-TP450:~$ docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
micro - generic Running tcp://10.10.11.137:2376 v17.03.2-ce
rancherOS - virtualbox Stopped Unknown
gws@gws-TP450:~$ eval $(docker-machine env micro)
gws@gws-TP450:~$ docker version
Client:
Version: 17.03.2-ce
API version: 1.27
Go version: go1.7.5
Git commit: f5ec1e2
Built: Tue Jun 27 03:35:14 2017
OS/Arch: linux/amd64
Server:
Version: 17.03.2-ce
API version: 1.27 (minimum version 1.12)
Go version: go1.7.5
Git commit: f5ec1e2
Built: Tue Jun 27 03:35:14 2017
OS/Arch: linux/amd64
Experimental: false
gws@gws-TP450:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
gws@gws-TP450:~$ eval $(docker-machine env --unset)