docker三剑客之docker-machine
Posted wangyp
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了docker三剑客之docker-machine相关的知识,希望对你有一定的参考价值。
#安装docker-machine [email protected]:~$ pwd /home/cupid [email protected]:~$ ls Desktop docker-machine-Linux-x86_64 Documents Downloads examples.desktop Music Pictures Public Templates Videos [email protected]:~$ mv docker-machine-Linux-x86_64 docker-machine [email protected]:~$ chmod +x docker-machine [email protected]:~$ sudo scp docker-machine /usr/local/bin/docker-machine [email protected]:~$ docker-machine version #安装成功 docker-machine version 0.12.2, build 9371605 ## [email protected]:~$ cd /etc/bash_completion.d/ [email protected]:/etc/bash_completion.d$ ls apport_completion git-prompt insserv desktop-file-validate grub libreoffice.sh [email protected]:/etc/bash_completion.d$ vi docker-machine-prompt.bash ~ ##添加被管理节点 1)生成ssh-key并拷贝到被管理节点 [email protected]:~# ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): /root/.ssh/id_rsa already exists. Overwrite (y/n)? y Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: SHA256:vleIKvWOKKZLtgNiZOe2z1U13xuuYLXKReYq1/Z/O74 [email protected] The key‘s randomart image is: +---[RSA 2048]----+ | | | | | o | | o . . o . | |o o So . = o | |o. o ..o . * o o| |+o. .. +. +.+ o | |o.+.o.o..o+.=o...| |o=..o+..o.o+..oEB| +----[SHA256]-----+ [email protected]:~# ssh-copy-id 192.168.142.169 /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub" /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys [email protected]‘s password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh ‘192.168.142.169‘" and check to make sure that only the key(s) you wanted were added. [email protected]:~# ssh-copy-id 192.168.142.170 /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub" The authenticity of host ‘192.168.142.170 (192.168.142.170)‘ can‘t be established. ECDSA key fingerprint is SHA256:nMYNsS3zGCBuh8jVYGG4XRieWfH0SvvAMIhz2O+bZKc. Are you sure you want to continue connecting (yes/no)? yes /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys [email protected]‘s password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh ‘192.168.142.170‘" and check to make sure that only the key(s) you wanted were added. #无需输入密码可登陆169 [email protected]:~# ssh 192.168.142.169 Welcome to Ubuntu 16.04.2 LTS (GNU/Linux 4.10.0-28-generic x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage 52 packages can be updated. 1 update is a security update. 2)添加被管理节点 因为是虚拟机,指定普通操作系统即可 [email protected]:~# docker-machine create --driver generic --generic-ip-address=192.168.142.169 host1 Creating CA: /root/.docker/machine/certs/ca.pem Creating client certificate: /root/.docker/machine/certs/cert.pem Running pre-create checks... Creating machine... (host1) 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 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 host1 #查看添加的主机 [email protected]:~# docker-machine ls NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS host1 - generic Running tcp://192.168.142.169:2376 v17.06.0-ce ~ ~ 3)如何管理节点的docker [[email protected]:~]#echo $PS1 [\[email protected]\h:\w$(__docker_machine_ps1)]\$ [[email protected]:~]#docker-machine ls NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS host1 - generic Running tcp://192.168.142.169:2376 v17.06.0-ce host2 - generic Running tcp://192.168.142.170:2376 v17.06.0-ce #查看连接到host1需要的环境变量 [[email protected]:~]#docker-machine env host1 export DOCKER_TLS_VERIFY="1" export DOCKER_HOST="tcp://192.168.142.169:2376" export DOCKER_CERT_PATH="/root/.docker/machine/machines/host1" export DOCKER_MACHINE_NAME="host1" # Run this command to configure your shell: # eval $(docker-machine env host1) #查看连接到host2需要的环境变量 [[email protected]:~]#docker-machine env host2 export DOCKER_TLS_VERIFY="1" export DOCKER_HOST="tcp://192.168.142.170:2376" export DOCKER_CERT_PATH="/root/.docker/machine/machines/host2" export DOCKER_MACHINE_NAME="host2" # Run this command to configure your shell: # eval $(docker-machine env host2) #eval此环境变量即可连接到host2的docker [[email protected]:~]#eval $(docker-machine env host2) [[email protected]:~ [host2]]#docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 87300fa502e3 busybox "sh" About an hour ago Exited (0) About an hour ago focused_cray aea28d5d7030 busybox "-it" About an hour ago Created keen_noether c9370139a79e httpd "httpd-foreground" 5 days ago Exited (255) 2 hours ago 80/tcp quirky_hypatia e5deab94f264 centos "/bin/bash -c ‘whi..." 5 days ago Exited (255) 2 hours ago romantic_johnson d19d1c95874f registry:2 "/entrypoint.sh /e..." 5 days ago Exited (255) 2 hours ago 0.0.0.0:5000->5000/tcp hardcore_colden ~
以上是关于docker三剑客之docker-machine的主要内容,如果未能解决你的问题,请参考以下文章
docker三剑客之应用machine,compose,swarm
企业运维实战--Docker三剑客一之docker-machine