Docker machine(Docker 虚拟机)

Posted 答案

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Docker machine(Docker 虚拟机)相关的知识,希望对你有一定的参考价值。

安装docker

[[email protected] ~]# yum -y install  docker

启动docker

[[email protected] ~]# systemctl start docker

下载Docker Machine二进制文件并将其解压缩到PATH

[[email protected] ~]# curl -L https://github.com/docker/machine/releases/download/v0.12.2/docker-machine-`uname -s`-`uname -m` >/tmp/docker-machine &&
chmod +x /tmp/docker-machine &&
sudo cp /tmp/docker-machine /usr/local/bin/docker-machine

检查安装版本

 [[email protected] ~]# docker-machine version
 docker-machine version 0.12.2, build 9371605

 

创建一台虚拟机

命令

docker-machine create -d virtualbox VMname

如果遇到以下问题

[[email protected] ~]# docker-machine create -d virtualbox VMname
Creating CA: /root/.docker/machine/certs/ca.pem
Creating client certificate: /root/.docker/machine/certs/cert.pem
Running pre-create checks...
Error with pre-create check: "VBoxManage not found. Make sure VirtualBox is installed
and VBoxManage is in the path"

上传安装包,下载地址

链接:http://pan.baidu.com/s/1slpxVzv 密码:qrlk

安装依赖并安装 VirtualBox

[[email protected] ~]# yum -y localinstall VirtualBox-5.1-5.1.20_114628_el7-1.x86_64.rpm 

再次创建

[[email protected] ~]# docker-machine create -d virtualbox VMname

查看新建的机器

[[email protected] ~]# docker-machine ls
NAME      ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKERORS
default   -        VMname   Running   tcp://192.168.99.100:2376           v17.0

获取新虚拟机的环境信息

[[email protected] ~]# docker-machine env VMname
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.100:2376"
export DOCKER_CERT_PATH="/root/.docker/machine/machines/default"
export DOCKER_MACHINE_NAME="default"
# Run this command to configure your shell: 
# eval $(docker-machine env default)

将宿主机的环境变量导入到创建的虚拟机当中

[[email protected] ~]# eval $(docker-machine env VMname)

查看虚拟机IP

[[email protected] ~]# docker-machine ip VMname

查看全部虚拟机和IP

[[email protected] ~]# docker-machine ls

进入到新创建的虚拟机

[[email protected] ~]# docker-machine ssh VMname

下载nginx 镜像

[email protected]:~$ docker pull nginx

安装Nginx

[email protected]:~$ docker run -d -p 8000:80 --name nginx01 nginx

也可以在虚拟机外安装Nginx

[[email protected] ~]# docker-machine ssh VMnaem docker pull nginx
[[email protected] ~]# docker-machine ssh VMname run -d -p 8000:80 --name nginx01 nginx

访问nginx

[[email protected] ~]# docker-machine ssh VMname curl -I 192.168.99.101:8000
HTTP/1.1 200 OK
Server: nginx/1.13.3
Date: Sat, 02 Sep 2017 09:39:32 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 11 Jul 2017 13:06:07 GMT
Connection: keep-alive
ETag: "5964cd3f-264"
Accept-Ranges: bytes

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0   612    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0

启动

[[email protected] ~]# docker-machine start VMname

停止

[[email protected] ~]# docker-machine stop  VMname

重启

[[email protected] ~]# docker-machine restart VMname

 

以上是关于Docker machine(Docker 虚拟机)的主要内容,如果未能解决你的问题,请参考以下文章

Docker三剑客之docker-machine

Docker Machine 简介

Docker Machine 简介

Docker Toolbox虚拟机文件地址修改 以及镜像加速

容器技术|Docker三剑客之docker-machine

虚拟机与Docker有何不同