Docker Machine 入门实践@FreeBSD

时间:2024-04-28 15:07:47

在这篇文档里,我们安装了docker machine:FreeBSD安装Docker记录-****博客

在这篇文档里,我们启动虚拟主机myvm并进入虚拟主机:boot2docker实践@FreeBSD-****博客

现在开始更深入的进行 docker的实战演练。参考Docker Machine官方文档:Docker Machine |

 

 Docker Machine 入门实践

基本操作

在FreeBSD系统中,使用docker-machine命令查看一下docker:

docker-machine ls
NAME       ACTIVE   DRIVER       STATE     URL   SWARM   DOCKER    ERRORS
myvm       *        virtualbox   Running                 Unknown   Machine does not have a host-only adapter
testmyvm   -        virtualbox   Stopped                 Unknown   

就像前面文档中讲到的,可以使用如下命令创建一个:

docker-machine create --driver virtualbox test

查询docker ip

docker-machine ip myvm

停止和启动

docker-machine  stop myvm
docker-machine  start myvm

进入机器

docker-machine ssh myvm

进阶操作

查看虚拟主机的情况

docker-machine inspect  myvm

输出信息

{
    "ConfigVersion": 3,
    "Driver": {
        "IPAddress": "",
        "MachineName": "myvm",
        "SSHUser": "docker",
        "SSHPort": 0,
        "SSHKeyPath": "",
        "StorePath": "/home/skywalk/.docker/machine",
        "SwarmMaster": false,
        "SwarmHost": "tcp://0.0.0.0:3376",
        "SwarmDiscovery": "",
        "VBoxManager": {},
        "HostInterfaces": {},
        "CPU": 1,
        "Memory": 1024,
        "DiskSize": 20000,
        "NatNicType": "82540EM",
        "Boot2DockerURL": "",
        "Boot2DockerImportVM": "",
        "HostDNSResolver": false,
        "HostOnlyCIDR": "192.168.99.1/24",
        "HostOnlyNicType": "82540EM",
        "HostOnlyPromiscMode": "deny",
        "UIType": "headless",
        "HostOnlyNoDHCP": false,
        "NoShare": false,
        "DNSProxy": true,
        "NoVTXCheck": false,
        "ShareFolder": ""
    },
    "DriverName": "virtualbox",
    "HostOptions": {
        "Driver": "",
        "Memory": 0,
        "Disk": 0,
        "EngineOptions": {
            "ArbitraryFlags": [],
            "Dns": null,
            "GraphDir": "",
            "Env": [],
            "Ipv6": false,
            "InsecureRegistry": [],
            "Labels": [],
            "LogLevel": "",
            "StorageDriver": "",
            "SelinuxEnabled": false,
            "TlsVerify": true,
            "RegistryMirror": [],
            "InstallURL": "https://get.docker.com"
        },
        "SwarmOptions": {
            "IsSwarm": false,
            "Address": "",
            "Discovery": "",
            "Agent": false,
            "Master": false,
            "Host": "tcp://0.0.0.0:3376",
            "Image": "swarm:latest",
            "Strategy": "spread",
            "Heartbeat": 0,
            "Overcommit": 0,
            "ArbitraryFlags": [],
            "ArbitraryJoinFlags": [],
            "Env": null,
            "IsExperimental": false
        },
        "AuthOptions": {
            "CertDir": "/home/skywalk/.docker/machine/certs",
            "CaCertPath": "/home/skywalk/.docker/machine/certs/ca.pem",
            "CaPrivateKeyPath": "/home/skywalk/.docker/machine/certs/ca-key.pem",
            "CaCertRemotePath": "",
            "ServerCertPath": "/home/skywalk/.docker/machine/machines/myvm/server.pem",
            "ServerKeyPath": "/home/skywalk/.docker/machine/machines/myvm/server-key.pem",
            "ClientKeyPath": "/home/skywalk/.docker/machine/certs/key.pem",
            "ServerCertRemotePath": "",
            "ServerKeyRemotePath": "",
            "ClientCertPath": "/home/skywalk/.docker/machine/certs/cert.pem",
            "ServerCertSANs": [],
            "StorePath": "/home/skywalk/.docker/machine/machines/myvm"
        }
    },
    "Name": "myvm"
}

 现在还无法通过docker-machine命令获得虚拟机的ip地址等信息,只好到virtual box中查看ip,发现是192.168.5.102 ,可以通过ssh来登录它。

ssh docker@192.168.56.102
docker@192.168.56.102's password: 
   ( '>')
  /) TC (\   Core is distributed with ABSOLUTELY NO WARRANTY.
 (/-_--_-\)           www.tinycorelinux.net

docker@boot2docker:~$ 

这样至少也可以开始后面的docker操作了。

总结:

前段时间整docker的时候,弄出来的docker-machine ,现在终于算是会玩了。

整个流程就是:

FreeBSD下使用pkg install docker-machine安装docker-machine,

然后可以使用docker-machine命令创建tiny-linux核心的boot2docker虚拟主机,并可在virtual-box中启动这个虚拟主机。boot2docker虚拟主机里面有全套的docker实现套件,这样就可以开始docker之旅了。

这就是在FreeBSD系统下进行docker的终极解决方案。

boot2docker本来是为了mac os和windows下使用docker而生的,但是后来mac和win下都有了docker实现,反而现在成了FreeBSD下的解决方案,真是事事难料、造化弄人啊! 

调试

虚拟机报错Error getting IP address: Machine does not have a host-only adapter

在vitrual-machine里给myvm虚拟机设定一块host-only的网卡

命令docker-machine ip报错err     : exit status 255

docker-machine ip myvm
(docker@127.0.0.1) Password for docker@x250:
(docker@127.0.0.1) Password for docker@x250:
(docker@127.0.0.1) Password for docker@x250:
Error getting IP address: ssh command error:
command : ip addr show
err     : exit status 255
output  :
提示需要输入docker的密码,我要想想...

问题是这个密码是啥时候输入、设定的啊!先保留问题,后面发现可以暂时不输入口令跳过,但是不知道这样处理是否正确(感觉肯定是有问题的)

docker-machine  start myvm 报错

docker-machine start  myvm
Starting "myvm"...
(myvm) Check network to re-create if needed...
(myvm) Found a new host-only adapter: "vboxnet16"
Error setting up host only network on machine start: /usr/local/bin/VBoxManage hostonlyif ipconfig vboxnet16 --ip 192.168.99.1 --netmask 255.255.255.0 failed:
VBoxManage: error: Code E_ACCESSDENIED (0x80070005) - Access denied (extended info not available)
VBoxManage: error: Context: "EnableStaticIPConfig(Bstr(pszIp).raw(), Bstr(pszNetmask).raw())" at line 242 of file VBoxManageHostonly.cpp
 

这个没解决,暂时采用到Virtual-box里面手动开机处理。

boot2docker默认的用户名和密码

在 boot2docker 中,默认的用户名和密码是:

user: docker pass: tcuser

登录方法:

$ ssh docker@localhost -p 2022

不过这个登录方法,在FreeBSD下,还没法用,因为根本就没看到2022端口啊。