docker三剑客之docker-machine
生活随笔
收集整理的這篇文章主要介紹了
docker三剑客之docker-machine
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
#安裝docker-machine
cupid@ubuntu:~$ pwd
/home/cupid
cupid@ubuntu:~$ ls
Desktop docker-machine-Linux-x86_64 Documents Downloads examples.desktop Music Pictures Public Templates Videos
cupid@ubuntu:~$ mv docker-machine-Linux-x86_64 docker-machine
cupid@ubuntu:~$ chmod +x docker-machine
cupid@ubuntu:~$ sudo scp docker-machine /usr/local/bin/docker-machine
cupid@ubuntu:~$ docker-machine version #安裝成功
docker-machine version 0.12.2, build 9371605
##
cupid@ubuntu:~$ cd /etc/bash_completion.d/
cupid@ubuntu:/etc/bash_completion.d$ ls
apport_completion git-prompt insserv
desktop-file-validate grub libreoffice.sh
cupid@ubuntu:/etc/bash_completion.d$ vi docker-machine-prompt.bash
~
##添加被管理節點
1)生成ssh-key并拷貝到被管理節點
root@ubuntu:~# 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 root@ubuntu
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]-----+
root@ubuntu:~# 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
root@192.168.142.169's password: Number of key(s) added: 1Now 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.root@ubuntu:~# 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
root@192.168.142.170's password: Number of key(s) added: 1Now 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
root@ubuntu:~# 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/advantage52 packages can be updated.
1 update is a security update.
2)添加被管理節點 因為是虛擬機,指定普通操作系統即可
root@ubuntu:~# 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
#查看添加的主機
root@ubuntu:~# 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
[root@host1:~]#echo $PS1
[\u@\h:\w$(__docker_machine_ps1)]\$
[root@host1:~]#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需要的環境變量
[root@host1:~]#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需要的環境變量
[root@host1:~]#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
[root@host1:~]#eval $(docker-machine env host2)[root@host1:~ [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
~
?
轉載于:https://www.cnblogs.com/wanyp/p/7257457.html
總結
以上是生活随笔為你收集整理的docker三剑客之docker-machine的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Apache配置网站根目录
- 下一篇: jquery on()事件