文档章节

(五)Docker三剑客之Machine

o
 osc_1ee7cxmx
发布于 2018/08/06 14:40
字数 997
阅读 10
收藏 0

Docker Machine 是 Docker 官方编排( Orchestration) 项目之一,负责在多种平台上快速安装 Docker 环境。 Docker Machine 项目基于 Go 语言实现,目前在 Github 上进行维护。

参考:

1. docker-machine 下载安装

  1. 下载
[root@Thor ]# curl -L https://github.com/docker/machine/releases/download/v0.13.0/docker-machine-`uname -s`-`uname -m` > /usr/local/bin/docker-machine
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   617    0   617    0     0    434      0 --:--:--  0:00:01 --:--:--   433
100 25.3M  100 25.3M    0     0  1338k      0  0:00:19  0:00:19 --:--:-- 4264k
[root@Thor compose]# chmod +x /usr/local/bin/docker-machine
  1. 查看版本
[root@Thor compose]# docker-machine version
docker-machine version 0.13.0, build 9ba6da9
  1. 查看help
[root@Thor compose]# docker-machine help
Usage: docker-machine [OPTIONS] COMMAND [arg...]

Create and manage machines running Docker.

Version: 0.13.0, build 9ba6da9

Author:
  Docker Machine Contributors - <https://github.com/docker/machine>

Options:
  --debug, -D					Enable debug mode
  --storage-path, -s "/root/.docker/machine"	Configures storage path [$MACHINE_STORAGE_PATH]
  --tls-ca-cert 				CA to verify remotes against [$MACHINE_TLS_CA_CERT]
  --tls-ca-key 					Private key to generate certificates [$MACHINE_TLS_CA_KEY]
  --tls-client-cert 				Client cert to use for TLS [$MACHINE_TLS_CLIENT_CERT]
  --tls-client-key 				Private key used in client TLS auth [$MACHINE_TLS_CLIENT_KEY]
  --github-api-token 				Token to use for requests to the Github API [$MACHINE_GITHUB_API_TOKEN]
  --native-ssh					Use the native (Go-based) SSH implementation. [$MACHINE_NATIVE_SSH]
  --bugsnag-api-token 				BugSnag API token for crash reporting [$MACHINE_BUGSNAG_API_TOKEN]
  --help, -h					show help
  --version, -v					print the version
  
Commands:
  active		Print which machine is active
  config		Print the connection config for machine
  create		Create a machine
  env			Display the commands to set up the environment for the Docker client
  inspect		Inspect information about a machine
  ip			Get the IP address of a machine
  kill			Kill a machine
  ls			List machines
  provision		Re-provision existing machines
  regenerate-certs	Regenerate TLS Certificates for a machine
  restart		Restart a machine
  rm			Remove a machine
  ssh			Log into or run a command on a machine with SSH.
  scp			Copy files between machines
  mount			Mount or unmount a directory from a machine with SSHFS.
  start			Start a machine
  status		Get the status of a machine
  stop			Stop a machine
  upgrade		Upgrade a machine to the latest version of Docker
  url			Get the URL of a machine
  version		Show the Docker Machine version or a machine docker version
  help			Shows a list of commands or help for one command
  
Run 'docker-machine COMMAND --help' for more information on a command.
[root@Thor compose]# 

2. virtualbox 的安装使用docker-machine 需要安装virtualbox

  1. 添加yum源
[root@Thor yum.repos.d] cd /etc/yum.repos.d/
[root@Thor yum.repos.d] touch virtualbox.repo

[root@Thor yum.repos.d]# cat virtualbox.repo 
[virtualbox]
name=Oracle Linux / RHEL / CentOS-$releasever / $basearch - VirtualBox
baseurl=http://download.virtualbox.org/virtualbox/rpm/el/$releasever/$basearch
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=https://www.virtualbox.org/download/oracle_vbox.asc
  1. 安装 VirtualBox-5.2
yum install -y VirtualBox-5.2

3. 创建docker主机

[root@Thor yum.repos.d]# docker-machine create -d virtualbox manager
Running pre-create checks...
(manager) Image cache directory does not exist, creating it at /root/.docker/machine/cache...
(manager) No default Boot2Docker ISO found locally, downloading the latest release...
(manager) Latest release for github.com/boot2docker/boot2docker is v18.06.0-ce
(manager) Downloading /root/.docker/machine/cache/boot2docker.iso from https://github.com/boot2docker/boot2docker/releases/download/v18.06.0-ce/boot2docker.iso...
Error with pre-create check: "Get https://github-production-release-asset-2e65be.s3.amazonaws.com/14930729/6d1e7256-8b4a-11e8-9a24-a19446163c40?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20180726%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20180726T092243Z&X-Amz-Expires=300&X-Amz-Signature=7647b3962d30f593b7d6d678c49d93412ca0ede14e17d6d12e452bfd19db9290&X-Amz-SignedHeaders=host&actor_id=0&response-content-disposition=attachment%3B%20filename%3Dboot2docker.iso&response-content-type=application%2Foctet-stream: dial tcp 52.216.224.112:443: getsockopt: connection timed out"

[root@Thor yum.repos.d]# cd /root/.docker/machine/cache/
[root@Thor cache]# ls
[root@Thor cache]# 

下载https://github.com/boot2docker/boot2docker/releases/download/v18.06.0-ce/boot2docker.iso,并放入到/root/.docker/machine/cache/目录下

[root@Thor machine]# cd /root/.docker/machine/cache/
[root@Thor cache]# ls
boot2docker.iso

创建一个machine

[root@Thor machine]# docker-machine create -d virtualbox manager
Running pre-create checks...
Creating machine...
(manager) Copying /root/.docker/machine/cache/boot2docker.iso to /root/.docker/machine/machines/manager/boot2docker.iso...
(manager) Creating VirtualBox VM...
(manager) Creating SSH key...
(manager) Starting the VM...
(manager) Check network to re-create if needed...
(manager) Waiting for an IP...
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 boot2docker...
Copying certs to the local machine directory...
Copying certs to the remote machine...
Setting Docker configuration on the remote daemon...

This machine has been allocated an IP address, but Docker Machine could not
reach it successfully.

SSH for the machine should still work, but connecting to exposed ports, such as
the Docker daemon port (usually <ip>:2376), may not work properly.

You may need to add the route manually, or use another related workaround.

This could be due to a VPN, proxy, or host file configuration issue.

You also might want to clear any VirtualBox host only interfaces you are not using.
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 manager
[root@Thor machine]# 

4. docker-machine ls 命令

[root@Thor cache]# docker-machine ls
NAME      ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER        ERRORS
manager   -        virtualbox   Running   tcp://192.168.99.100:2376           v18.06.0-ce 

5. 通过ssh连接到docker主机

[root@Thor cache]# docker-machine ssh manager
                        ##         .
                  ## ## ##        ==
               ## ## ## ## ##    ===
           /"""""""""""""""""\___/ ===
      ~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ /  ===- ~~~
           \______ o           __/
             \    \         __/
              \____\_______/
 _                 _   ____     _            _
| |__   ___   ___ | |_|___ \ __| | ___   ___| | _____ _ __
| '_ \ / _ \ / _ \| __| __) / _` |/ _ \ / __| |/ / _ \ '__|
| |_) | (_) | (_) | |_ / __/ (_| | (_) | (__|   <  __/ |
|_.__/ \___/ \___/ \__|_____\__,_|\___/ \___|_|\_\___|_|
Boot2Docker version 18.06.0-ce, build HEAD : 1f40eb2 - Thu Jul 19 18:48:09 UTC 2018
Docker version 18.06.0-ce, build 0ffa825
docker@manager:~$ docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
docker@manager:~$ 

连接到主机之后你就可以在其上使用 Docker 了.

上一篇: 稳定婚姻模型
o
粉丝 0
博文 500
码字总数 0
作品 0
私信 提问
加载中
请先登录后再评论。

暂无文章

在virtualenv中使用Python 3 - Using Python 3 in virtualenv

问题: Using virtualenv , I run my projects with the default version of Python (2.7). 使用virtualenv ,我使用默认版本的Python(2.7)运行项目。 On one project, I need to use Pyth......

富含淀粉
22分钟前
9
0
Python的__init__和self是做什么的? - What __init__ and self do on Python?

问题: I'm learning the Python programming language and I've came across something I don't fully understand. 我正在学习Python编程语言,遇到了一些我不太了解的东西。 In a method ......

javail
52分钟前
15
0
OSChina 周五乱弹 —— 你大妈还是你大妈

Osc乱弹歌单(2020)请戳(这里) 【今日歌曲】 @watergood:是时候分享一波我的这张纯音乐歌单了,过去的五年多时间里,我陆陆续续地把听到的好听的纯音乐添加了进去,目前一共65首,相信总...

小小编辑
今天
25
0
在Objective-C中生成随机数 - Generating random numbers in Objective-C

问题: I'm a Java head mainly, and I want a way to generate a pseudo-random number between 0 and 74. In Java I would use the method: 我主要是Java头,我想要一种生成0到74之间的伪随......

技术盛宴
今天
13
0
ftp-ftps-sftp的关系

Ftp FTP 是File Transfer Protocol(文件传输协议)的英文简称,而中文简称为“文传协议”。用于Internet上的控制文件的双向传输。同时,它也是一个应用程序(Application)。基于不同的操作...

独钓渔
今天
12
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部