【Hackintosh】AMD Ryzen Hackintosh 安装 Docker

Posted by 西维蜀黍 on 2021-04-24, Last Modified on 2022-04-01

Error

Docker Machine

https://github.com/docker/machine

https://docker-docs.netlify.app/machine/overview/

VirtualBox

Solution - Docker Machine

A VirtualBox host-only network adapter is used to facilitate communication between the Docker client running on the physical host and the Docker daemon within the boot2docker VM. VirtualBox normally adds routes for this to the routing table.

Pre-install

Otherwise, you may see this error (VBoxManage not found. Make sure VirtualBox is installed and VBoxManage is in the path):

$ docker-machine ls
NAME      ACTIVE   DRIVER       STATE   URL   SWARM   DOCKER    ERRORS
default   -        virtualbox   Error                 Unknown   VBoxManage not found. Make sure VirtualBox is installed and VBoxManage is in the path

Docker installation via Homebrew

$ brew install docker

Docker-Machine installation via Homebrew

$ brew install docker-machine

VirtualBox installation via Homebrew

$ brew install virtualbox --cask

Create a new virtual machine

Then, let’s create a machine. You can create a machine by docker-machine create (name)with--driver flag to specify a provide on which the machine is created on. (docker doc)

$ docker-machine create --driver virtualbox default

[...]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 default

You may see this error. If so, turn on AMD-V in BIOS

Error creating machine: Error in driver during machine creation: Unable to start the VM: /usr/local/bin/VBoxManage startvm default --type headless failed:
VBoxManage: error: AMD-V is disabled in the BIOS (or by the host OS) (VERR_SVM_DISABLED)
VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component ConsoleWrap, interface IConsole

Details: 00:00:00.159192 Power up failed (vrc=VERR_SVM_DISABLED, rc=NS_ERROR_FAILURE (0X80004005))

Run docker-machine ls and you’ll see your ‘default’ machine is now created.

$ docker-machine ls
NAME      ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER     ERRORS
default   *        virtualbox   Running   tcp://192.168.xxx.xxx:xxxx           v18.09.5

Few more steps. As noted in the output of the docker-machine create command, run the following command to tell the Docker ‘which machine’ to execute docker command to.

$ docker-machine env default

And connect your shell to the new machine. Here I’m using zsh (Docker supports bash cmd powershell emacs , fish and SHELL can be OK).

$ eval $(docker-machine env default)

Finally, let’s check that all installation process is achieved correctly!

$ docker run hello-world

When you finish playing around with Docker this time, don’t forget to stop the machine with this command. ( You can check the status docker-machine ls)

$ docker-machine stop default

Auto Start

This is a simple launchd config that will start your default docker-machine on startup. You can customize the machine that is started by updating lines 11 and 16 with the correct machine name.

com.docker.machine.default.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>EnvironmentVariables</key>
        <dict>
            <key>PATH</key>
            <string>/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin</string>
        </dict>
        <key>Label</key>
        <string>com.docker.machine.default</string>
        <key>ProgramArguments</key>
        <array>
            <string>/usr/local/bin/docker-machine</string>
            <string>start</string>
            <string>default</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
    </dict>
</plist>

Copy the file com.docker.machine.default.plist below to ~/Library/LaunchAgents/com.docker.machine.default.plist.

Run the following in a terminal

$ launchctl load ~/Library/LaunchAgents/com.docker.machine.default.plist

$ docker run hello-world

SSH to the virtual machine

$ docker-machine ssh default

Troubleshooting

failed to open /dev/vboxnetctl

$ docker-machine restart default
Restarting "default"...
Starting "default"...
(default) Check network to re-create if needed...
(default) Creating a new host-only adapter produced an error: /usr/local/bin/VBoxManage hostonlyif create failed:
(default) 0%...
(default) Progress state: NS_ERROR_FAILURE
(default) VBoxManage: error: Failed to create the host-only adapter
(default) VBoxManage: error: VBoxNetAdpCtl: Error while adding new interface: failed to open /dev/vboxnetctl: No such file or directory
(default) VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component HostNetworkInterfaceWrap, interface IHostNetworkInterface
(default) VBoxManage: error: Context: "RTEXITCODE handleCreate(HandlerArg *)" at line 95 of file VBoxManageHostonly.cpp
  1. Grant permission to VirtualBox under System Preferences > Security & Privacy > General (this request is new to macOS High Sierra)
  2. Open Terminal and run: sudo "/Library/Application Support/VirtualBox/LaunchDaemons/VirtualBoxStartup.sh" restart

每次使用

$ eval $(docker-machine env default)

$ docker run hello-world

Error checking TLS connection: Machine does not have a host-only adapter

$ eval $(docker-machine env default)
Error checking TLS connection: Machine does not have a host-only adapter

这是因为 virtual machine 必须包含一个 host-only adapter,如果没有包含,则会报此错。

This machine has been allocated an IP address, but Docker Machine could not reach it successfully.

$ docker-machine create -d virtualbox default
...
This machine has been allocated an IP address, but Docker Machine could not
reach it successfully.

SSH for the machine should still work, but connecting to exposed ports, such as
the Docker daemon port (usually <ip>:2376), may not work properly.

You may need to add the route manually, or use another related workaround.

This could be due to a VPN, proxy, or host file configuration issue.

You also might want to clear any VirtualBox host only interfaces you are not using.
Checking connection to Docker...
Error creating machine: Error checking the host: Error checking and/or regenerating the certs: There was an error validating certificates for host "192.168.99.109:2376": dial tcp 192.168.99.109:2376: i/o timeout
You can attempt to regenerate them using 'docker-machine regenerate-certs [name]'.
Be advised that this will trigger a Docker daemon restart which might stop running containers.

我们来分析一下

  • dial tcp 192.168.99.109:2376: i/o timeout 错误说明 这个端口不能被访问到

  • 因而,我们首先检查host到 virtual host 的链路是否正常,通过

    •   $ ping 192.168.99.109
        PING 192.168.99.109 (192.168.99.109): 56 data bytes
        Request timeout for icmp_seq 0
        Request timeout for icmp_seq 1
        Request timeout for icmp_seq 2
      
    • 说明ping不通

  • 再检查路由表

    •   $ netstat -nr
        ...
      
    • 并没有到 192.168.99.109 的路由信息

  • 我们在VirtualBox的这个virtual machine的Network Setting中,增加一个 Bridged Adapter

  • 重启这个virtual machine,该virtual machine就会获得一个和当前宿主机所处网段内的一个IP(我的宿主机IP是192.168.18.68,这个virtual machine拿到了192.168.18.163)

    • 这个virtual machine的IP可以通过docker-machine ssh default 以SSH 进入该virtual machine,然后ifconfig看到
  • 在宿主机下添加路由信息sudo route add 192.168.99.1/24 192.168.18.163,以使得通过IP 192.168.99.109 能成功访问到这个 virtual machine

    • 在宿主机下 ping 一下 这个 virtual machine 以验证一下链路没有问题

    •   $ ping 192.168.99.109
        PING 192.168.99.109 (192.168.99.109): 56 data bytes
        64 bytes from 192.168.99.109: icmp_seq=0 ttl=64 time=0.361 ms
      
  • 一切正常,尝试在宿主机下让 docker-machine 访问这个 virtual machine 中跑的docker daemon

    •   $ docker-machine ls
        NAME      ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER      ERRORS
        default   -        virtualbox   Running   tcp://192.168.99.104:2376           v19.03.12
      
    • 再次说明一切正常

Cisco AnyConnect VPN 导致 docker-machine无法使用

Context

开启VPN后,发现

$ netstat -nr
...
192.168.18.163     8:0:27:56:fc:5e    UHLWI          en0   1182
192.168.99.104     link#18            UHW3Ig       utun2     14
...

因此再ping 这个 virtual machine 时,就ping不通了,同时自然地docker-machine也连不上virtual machine 中的 docker daemon

Solution

Use OpenConnect, refer to https://swsmile.info/post/openconnect/

Others

Solution 1

在宿主机下添加路由信息,以使得通过IP 192.168.99.109 能成功访问到这个 virtual machine
$ sudo route add 192.168.99.1/24 192.168.18.167
# or 
$ sudo networksetup -setadditionalroutes "Ethernet" 192.168.99.0 255.255.255.0 192.168.18.167

sudo route -v add -net 192.168.99.0/24 -interface vboxnet0

在我情况下,加入该路由规则后,查看路由表,路由表中并无该规则,因而该solution不work。

Solution 2

Forward ports and then just always use docker --tlsverify=false

Solution 3

I had a similar problem with IP conflicts on 192.168.x.x I solved it changing the subnet of the VirtualBox host-only network.

  1. run docker-machine rm dev
  2. Go into the VirtualBox preferences and remove the host-only network
  3. run docker-machine create --driver virtualbox --virtualbox-hostonly-cidr "25.0.1.100/24" dev

Ref

Ref

Reference