Docker Machine安装及使用

安装 Docker Machine

参考:https://docs.docker.com/machine/install-machine/

CentOS:

$ curl -L https://github.com/docker/machine/releases/download/v0.10.0/docker-machine-`uname -s`-`uname -m` >/tmp/docker-machine
$ chmod +x /tmp/docker-machine
$ sudo cp /tmp/docker-machine /usr/local/bin/docker-machine
$ docker-machine -v
docker-machine version 0.10.0, build 76ed2a6

Windows(使用git bash):

$ if [[ ! -d "$HOME/bin" ]]; then mkdir -p "$HOME/bin"; fi && \
  curl -L https://github.com/docker/machine/releases/download/v0.10.0/docker-machine-Windows-x86_64.exe > "$HOME/bin/docker-machine.exe" && \
  chmod +x "$HOME/bin/docker-machine.exe"

卸载 Docker Machine

直接移除可执行文件

rm $(which docker-machine)

移除创建的machines

(1)移除指定machine:

docker-machine rm <machine-name>

(2)移除所有machines:

docker-machine rm -f $(docker-machine ls -q)

安装Dockerized machines

创建 manager and worker machines

Linux/MAC在Shell下运行,Windows在CMD下运行

Linux/MAC

docker-machine create --driver virtualbox MACHINE-NAME

Windows 10 (运行Docker for Windows)

docker-machine create -d hyperv --hyperv-virtual-switch "NETWORK-SWITCH" MACHINE-NAME

注:Windows 10安装Docker for Windows后只能使用Hyper-V,否则启动一直停留在Docker is starting

Windows 7/8 (运行Docker ToolBox)

docker-machine create --driver virtualbox MACHINE-NAME
> docker-machine create --driver virtualbox manager  //Docker ToolBox
> docker-machine create --driver virtualbox worker
> docker-machine ls  //查看machine列表
NAME      ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER        ERRORS
default   -        virtualbox   Running   tcp://192.168.99.100:2376           v17.03.0-ce
manager   -        virtualbox   Running   tcp://192.168.99.101:2376           v17.03.0-ce
worker    -        virtualbox   Running   tcp://192.168.99.102:2376           v17.03.0-ce
> docker-machine ip manager  //查看IP信息
192.168.99.101

启动和停止 machines

停止指令:

> docker-machine stop <machine-name>

启动指令:

> docker-machine start <machine-name>
> docker-machine env <machine-name>

删除指令:

> docker-machine rm <machine-name>

与 machines 交互

通过预置的Shell连接Machine

> docker-machine env manager  //设置manager的环境变量
SET DOCKER_TLS_VERIFY=1
SET DOCKER_HOST=tcp://192.168.99.101:2376
SET DOCKER_CERT_PATH=C:\Users\yezhou\.docker\machine\machines\manager
SET DOCKER_MACHINE_NAME=manager
SET COMPOSE_CONVERT_WINDOWS_PATHS=true
REM Run this command to configure your shell:
REM     @FOR /f "tokens=*" %i IN ('docker-machine env manager') DO @%i

> @FOR /f "tokens=*" %i IN ('docker-machine env manager') DO @%i  //连接manager

> docker-machine ls  //manager的ACTIVE状态已变为*
NAME      ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER        ERRORS
default   -        virtualbox   Running   tcp://192.168.99.100:2376           v17.03.0-ce
manager   *        virtualbox   Running   tcp://192.168.99.101:2376           v17.03.0-ce
worker    -        virtualbox   Running   tcp://192.168.99.102:2376           v17.03.0-ce

> docker run hello-world  //在machine中执行操作

通过ssh连接Machine(在Windows的CMD下有乱码问题)

> docker-machine ssh worker
                        ##         .
                  ## ## ##        ==
               ## ## ## ## ##    ===
           /"""""""""""""""""\___/ ===
      ~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ /  ===- ~~~
           \______ o           __/
             \    \         __/
              \____\_______/
 _                 _   ____     _            _
| |__   ___   ___ | |_|___ \ __| | ___   ___| | _____ _ __
| '_ \ / _ \ / _ \| __| __) / _` |/ _ \ / __| |/ / _ \ '__|
| |_) | (_) | (_) | |_ / __/ (_| | (_) | (__|   <  __/ |
|_.__/ \___/ \___/ \__|_____\__,_|\___/ \___|_|\_\___|_|
Boot2Docker version 17.03.0-ce, build HEAD : f11a204 - Thu Mar  2 00:14:47 UTC 2017
Docker version 17.03.0-ce, build 3a232c8

通过第三方ssh工具连接Machine(在Windows下推荐)

如XShell、SecureCRT、Putty等

(1)Docker自带默认虚拟机:default

  • IP地址:192.168.99.100
  • 端口:22
  • 默认账户:docker
  • 默认密码:tcuser

(2)虚拟机:manager

  • IP地址:192.168.99.101
  • 端口:22
  • 默认账户:docker
  • 默认密码:tcuser

(3)虚拟机:worker

  • IP地址:192.168.99.102
  • 端口:22
  • 默认账户:docker
  • 默认密码:tcuser

docker-machine 的指令列表

  • docker-machine config
  • docker-machine env
  • docker-machine inspect
  • docker-machine ip
  • docker-machine kill
  • docker-machine provision
  • docker-machine regenerate-certs
  • docker-machine restart
  • docker-machine ssh
  • docker-machine start
  • docker-machine status
  • docker-machine stop
  • docker-machine upgrade
  • docker-machine url

版权声明:
作者:Joe.Ye
链接:https://www.appblog.cn/index.php/2023/02/26/docker-machine-install-and-use/
来源:APP全栈技术分享
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
打赏
海报
Docker Machine安装及使用
安装 Docker Machine 参考:https://docs.docker.com/machine/install-machine/ CentOS: $ curl -L https://github.com/docker/machine/releases/download/v……
<<上一篇
下一篇>>
文章目录
关闭
目 录