Docker-Machine常用操作命令
通过 VirtualBox 来介绍 docker-machine 的使用方法。
列出可用的机器
scriptdocker-machine ls
以下是执行结果:
scriptNAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS manager - virtualbox Stopped Unknown node1 - virtualbox Stopped Unknown node2 - virtualbox Stopped Unknown
作者这里显示了三个未运行的容器,是因为我之前已经操作过。若你是刚安装的用户,那你看到的应该是空列表。
创建机器
注:这里需要提前安装好 VirtualBox ,若你没有安装请参考 Docker-Machine环境搭建
scriptdocker-machine create --driver virtualbox test
--driver
: 指定用来创建机器的驱动类型,这里是 VirtualBox。
以下是执行结果:
scriptRunning pre-create checks... Creating machine... (test) Copying C:\Users\HP\.docker\machine\cache\boot2docker.iso to C:\Users\HP\.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) Windows might ask for the permission to configure a dhcp server. Sometimes, such confirmation window is minimized in the taskbar. (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: C:\Users\HP\bin\docker-machine.exe env test
查看机器的IP
scriptdocker-machine ip test
以下是执行结果:
script192.168.99.101
停止机器
scriptdocker-machine stop test
以下是执行结果:
scriptStopping "test"... Machine "test" was stopped.
启动机器
scriptdocker-machine start test
以下是执行结果:
scriptStarting "test"... (test) Check network to re-create if needed... (test) Windows might ask for the permission to configure a dhcp server. Sometimes, such confirmation window is minimized in the taskbar. (test) Waiting for an IP... Machine "test" was started. Waiting for SSH to be available... Detecting the provisioner... Started machines may have new IP addresses. You may need to re-run the `docker-machine env` command.
进入机器
scriptdocker-machine ssh test
以下是执行结果:
script( '>') ( '>') /) TC (\ Core is distributed with ABSOLUTELY NO WARRANTY. (/-_--_-\) www.tinycorelinux.net docker@test:~$
docker-machine 命令参数说明
docker-machine active
:查看当前激活状态的 Docker 主机。config
:查看当前激活状态 Docker 主机的连接信息。create
:创建 Docker 主机env
:显示连接到某个主机需要的环境变量inspect
: 以 json 格式输出指定Docker的详细信息ip
: 获取指定 Docker 主机的地址kill
: 直接杀死指定的 Docker 主机ls
: 列出所有的管理主机provision
: 重新配置指定主机regenerate-certs
: 为某个主机重新生成 TLS 信息restart
: 重启指定的主机rm
: 删除某台 Docker 主机,对应的虚拟机也会被删除ssh
: 通过 SSH 连接到主机上,执行命令scp
: 在 Docker 主机之间以及 Docker 主机和本地主机之间通过 scp 远程复制数据mount
: 使用 SSHFS 从计算机装载或卸载目录start
: 启动一个指定的 Docker 主机,如果对象是个虚拟机,该虚拟机将被启动status
: 获取指定 Docker 主机的状态(包括:Running、Paused、Saved、Stopped、Stopping、Starting、Error)等stop
: 停止一个指定的 Docker 主机upgrade
: 将一个指定主机的 Docker 版本更新为最新url
: 获取指定 Docker 主机的监听 URLversion
: 显示 Docker Machine 的版本或者主机 Docker 版本help
: 显示帮助信息
Docker-Machine常用操作命令
https://blog.cikaros.top/doc/d5d887b8.html