本文共 3132 字,大约阅读时间需要 10 分钟。
我们生产环节中一定是 多host出现的,所以我用到docker-machine 管理工具,实现对多个host上面的docker的管理。
1、安装docker-machine
设置环境变量;base=下载curl -L $base/docker-machine-$(uname -s)-$(uname -m) >/tmp/docker-machine 设置环境变量sudo install /tmp/docker-machine /usr/local/bin/docker-machine此时可以执行docer-machine 相关指令,验证是否成功[root@docker ~]# docker-machine --versiondocker-machine version 0.14.0, build 89b83322、添加主机
1、设置无密码登陆2、添加主机[root@docker ~]# docker-machine create --driver generic --generic-ip-address=192.168.1.39 dockerCreating CA: /root/.docker/machine/certs/ca.pemCreating client certificate: /root/.docker/machine/certs/cert.pemRunning pre-create checks...Creating machine...(docker) 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 docker我们先把自己添加进来此时查看执行这个命令的动作[root@docker ~]# ps -ef|grep yumroot 13455 13333 0 20:41 pts/2 00:00:00 /usr/bin/ssh -F /dev/null -o PasswordAuthentication=no -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=quiet -o ConnectionAttempts=3 -o ConnectTimeout=10 -o ControlMaster=no -o ControlPath=none root@192.168.1.39 -p 22 -tt sudo -E yum -y update -x docker-root 13459 13456 0 20:41 pts/3 00:00:00 sudo -E yum -y update -x docker-root 13472 13459 5 20:41 pts/3 00:00:13 /usr/bin/python /bin/yum -y update -x docker-*root 13572 13502 0 20:45 pts/5 00:00:00 grep --color=auto yum执行这个命令后,在升级安装 dicker 等插件验证是否添加完成
[root@docker ~]# docker-machine lsNAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORSdocker - generic Running tcp://192.168.1.39:2376 v1.13.1 [root@docker ~]#2、添加第二台 host主机 (第二台host 配置和yum源和ssh无密码登陆,什么也不用做)
[root@docker ~]# docker-machine create --driver generic --generic-ip-address=192.168.1.40 docker-1Running pre-create checks...Creating machine...(docker-1) 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 docker-1[root@docker ~]# docker-machine lsNAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORSdocker - generic Running tcp://192.168.1.39:2376 v1.13.1 docker-1 - generic Running tcp://192.168.1.40:2376 v18.05.0-ce [root@docker ~]#转载于:https://blog.51cto.com/shyln/2135037