Docker Machine 是 Docker 官方编排(Orchestration)项目之一,负责在多种平台上快速安装 Docker 环境,下面我们就来说一说关于docker使用分析?我们一起去了解并探讨一下这个问题吧!

docker使用分析(Docker进阶---DockerMachine介绍)

docker使用分析

Docker Machine 是 Docker 官方编排(Orchestration)项目之一,负责在多种平台上快速安装 Docker 环境。

Docker Machine 项目基于 Go 语言实现,目前在 Github 上进行维护。

1. 安装

docker Machine 可以在多种操作系统平台上安装,包括 Linux、macOS,以及 Windows。

在 Linux 上的也安装十分简单,从 官方 GitHub Release 处直接下载编译好的二进制文件即可。

例如,在 Linux 64 位系统上直接下载对应的二进制包:

[root@centos1 django]# 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 307 0 --:--:-- 0:00:02 --:--:-- 307 3 25.3M 3 934k 0 0 21156 0 0:20:56 0:00:45 0:20:11 30623 79 25.3M 79 20.1M 0 0 17349 0 0:25:31 0:20:16 0:05:15 29183 100 25.3M 100 25.3M 0 0 18003 0 0:24:36 0:24:36 --:--:-- 34820

查看版本:

[root@centos1 django]# docker-machine -v docker-machine version 0.13.0, build 9ba6da9

2. 使用

Docker Machine 支持多种后端驱动,包括虚拟机、本地主机和云平台等。

(1)创建本地主机实例【virtualbox 驱动】

使用 virtualbox 类型的驱动,创建一台 Docker 主机,命名为 test:

[root@centos1 django]# docker-machine create -d virtualbox test Running pre-create checks... Creating machine... (test) Copying /root/.docker/machine/cache/boot2docker.iso to /root/.docker/machine/machines/test/boot2docker.iso... (test) Creating VirtualBox VM... (test) Creating SSH key... (test) Starting the VM... (test) Check network to re-create if needed... (test) 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... 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 test

也可以在创建时加上如下参数,来配置主机或者主机上的 Docker。

--engine-opt dns=114.114.114.114 配置 Docker 的默认 DNS --engine-registry-mirror https://registry.docker-cn.com 配置 Docker 的仓库镜像 --virtualbox-memory 2048 配置主机内存 --virtualbox-cpu-count 2 配置主机 CPU

更多参数请使用 docker-machine create --driver virtualbox --help 命令查看。

(2)查看

[root@centos1 django]# docker-machine ls NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS test - virtualbox Running tcp://192.168.99.102:2376 v18.09.5

(3)使用

创建主机成功后,可以通过 env 命令来让后续操作对象都是目标主机。

$ docker-machine env test

后续根据提示在命令行输入命令之后就可以操作 test 主机。

也可以通过 SSH 登录到主机:

[root@centos1 django]# docker-machine ssh test ( '>') /) TC (\ Core is distributed with ABSOLUTELY NO WARRANTY. (/-_--_-\) www.tinycorelinux.net docker@test:~$ uname -a Linux test 4.14.111-boot2docker #1 SMP Fri Apr 5 23:05:10 UTC 2019 x86_64 GNU/Linux docker@test:~$ docker@test:~$ cat /etc/os-release NAME=Boot2Docker VERSION=18.09.5 ID=boot2docker ID_LIKE=tcl VERSION_ID=18.09.5 PRETTY_NAME="Boot2Docker 18.09.5 (TCL 8.2.1)" ANSI_COLOR="1;34" HOME_URL="https://github.com/boot2docker/boot2docker" SUPPORT_URL="https://blog.docker.com/2016/11/introducing-docker-community-directory-docker-community-slack/" BUG_REPORT_URL="https://github.com/boot2docker/boot2docker/issues" docker@test:~$ docker --version Docker version 18.09.5, build e8ff056dbc

3. 驱动

通过 -d 选项可以选择支持的驱动类型。

amazonec2 azure digitalocean exoscale generic google hyperv none openstack rackspace softlayer virtualbox vmwarevcloudair vmwarefusion vmwarevsphere

,