How to access a docker container running on MacOSX from another host?

后端 未结 5 543
时光取名叫无心
时光取名叫无心 2021-02-04 15:25

I\'m trying to get started with docker and want to run the Ubiquiti video controller. I have installed Docker Toolbox and managed to get the container to run on my Yosemite host

5条回答
  •  执念已碎
    2021-02-04 15:46

    On a machine with Docker Toolbox for Mac, I'm solving the problem as follows (using the default machine).

    Preparation

    1. Stop the machine if it's running:

      docker-machine stop default

    VirtualBox Setup

    1. Open VirtualBox, select the default machine, open Settings (Cmd-S), go to Network, and select "Adapter 3".

    2. Check "Enable Network Adapter" (turn it on).

    3. Set "Attached to" to "Bridged Adapter".
    4. Set Name to "en0: Ethernet" (or whatever is the primary network interface or your Mac).
    5. Disclose "Advanced", and make sure "Cable Connected" is checked on.
    6. Note the "MAC Address" of "Adapter 3" (we'll use it later).
    7. Press "OK" to save the settings.

    Docker Setup

    1. Now, back in Terminal, start the machine:

      docker-machine start default

    2. Just in case, regenerate the certs:

      docker-machine regenerate-certs default

    3. Update the environment:

      eval $(docker-machine env default)

    At this point, the machine should be running (with the default IP address of 192.168.99.100, accessible only from the hosting Mac). However, if you ssh into the docker VM (docker-machine ssh default) and run ifconfig -a, you'll see that one of the VM's interfaces (eth0 in my case) has an IP in the same network as your Mac (e.g. 192.168.0.102), which is accessible from other devices on your LAN.

    Router Setup

    Now, the last step is to make sure this address is fixed, and not changed from time to time by your router's DHCP. This may differ from router to router, the following applies to my no-frills TP-LINK router, but should be easily adjustable to other makes and models.

    1. Open your router settings, and first check that default is in the router's DHCP Clients List, with the MAC address from step 7 above.

    2. Open "DHCP" > "Address Reservation" in the router settings, and add the "Adapter 3" MAC Address (you may have to insert the missing dashes), and your desired IP there (e.g. 192.168.0.201).

    3. Now my router asks me to reboot it. After the reboot, run docker-machine restart default for the Docker VM to pick up its new IP address.

    4. Final verification: docker-machine ssh default, then ifconfig -a, and find your new IP address in the output (this time the interface was eth1).

    Result

    From the hosting Mac the machine is accessible via two addresses (192.168.99.100 and 192.168.0.201); from other devices in the LAN it's accessible as 192.168.0.201.

提交回复
热议问题