How to connect to a docker container from outside the host (same network) [OSX 10.11]
Asked Answered
I

2

9

The Setup:

  • Computer A - This is where the Docker-Machine "default" runs under VirtualBox. "default" is running a container called "Odoo". "default" was created using Docker's installation process. "Odoo" was created using Odoo's installation process.
  • Computer B - This is a computer on the same Local Area Network (LAN) as Computer A.
  • Router - This connects Computer A and Computer B together on the LAN.

The Software:

  • Computer A - OSX 10.11.3 / VirtualBox 5.0.18 / Docker 1.11
  • Computer B - Windows 7 / Firefox
  • Router - ASUSWRT

The Problem:

  • Odoo is accessible on Computer A using "default's" IP address plus Odoo's associated port number. An example of the address is: 192.168.99.101:8069.
  • Odoo is NOT accessible on Computer B using "default's" IP address plus Odoo's associated port number.

The Question:

  • How is the VirtualBox environment configured such that Computer B can access Odoo on the LAN?
Involuntary answered 28/4, 2016 at 17:49 Comment(0)
H
9

That 192.168.99.101 is Docker host’s IP address internal to Computer A. You only need to config port forwarding from defaut's port 8069 to host machine' port 8069. Then odoo will be accessible by computer B with computer A's ip address(ex: 10.0.1.22) plus port 8069. Since both computers are within the same network, you shouldn't need to change settings of your router(except firewall settings, if there is any)

10.0.1.22:8069

Port forwarding need to be set in virtulbox settings

enter image description here

enter image description here

Hebron answered 29/4, 2016 at 4:24 Comment(4)
Thanks @Awakening Byte. Your method is much cleaner than the one I posted. Early on I tried something similar but got the entries for the Rule wrong.Involuntary
@Awakening Byte I'm using Kitematic to run jupyter server inside docker containers on windows, the port exposed to the host seemed always to be changing. Is there a way to forward all port number greater than 30000 to 8888 in the VM?Wheen
For selenium-docker (hub and node in different machine) . I did following things 1) Port forwarding as described above on 'default' vm of computer A 2) registering node from computer B 3) port forwarding on 'default' vm of machine B also ... 3rd step is the important one , if you don't do this then selenium hub will not be able to communicate with docker image (where selenium node stays) of machine BOrlan
For Detailed explanation of above things in terms of selenium hub/node setup on different machine , Have a look at #40594302Orlan
I
3

Note!

The solution that involves modifying Network Adapter 1 is much easier to implement. It is the recommended solution.

The Background:

When Docker is installed a Virtual Machine (VM) known as "default" is created inside VirtualBox. Within VirtualBox Docker sets a network configuration that allows the host computer (Computer A) to access containers running on "default" via the docker-machine ip. But Computer B cannot access the same containers via the docker-machine ip.

The Basic Process:

  1. Adjust Settings of the VM "default" via Oracle's VM VirtualBox Manager to form a Bridged Network.
  2. Start the "default" VM.
  3. Find the Bridged Network IP (BN-IP) address of the "default" VM.
  4. Start the Odoo container.
  5. Enter the BN-IP address plus Odoo's port (ex. 192.168.1.93:8069) into Computer B's web browser.
  6. Enjoy (unless something goes wrong and when doesn't it go wrong?).

Adjust Settings of the VM "default"

  1. Open the VirtualBox GUI.
  2. Look at the list of VMs on the left side of the GUI.
  3. Click "default" (or the VM you'd like to modify)
  4. Click the "Settings" icon (gear object)
  5. Follow the screen shot. Note: If using an ethernet cable to connect with the LAN choose en0 rather than en1. MAC Address was removed for the screen shot. It should autofill.enter image description here

    Start the "default" VM

    For Mac it's easiest to start the "default" VM by clicking on the Docker QuickStart Terminal icon.

enter image description here

After a wait of a minute or two you'll be presented with a splash screen that includes the "default" IP. This is NOT the BN-IP you're looking for. enter image description here

Find the BN-IP address of the "default" VM

This is the part that's the key and ground me down for hours. Fortunately good network discovery instructions exist. Run the instructions in the Docker Terminal and an address for "default.YourLANDomain" should turn up. It'll look something like:


default.ripcord.lan (192.168.1.93) at x:x:xx:xx:xx:xx on en1 ifscope [ethernet]

Notice the "default" part of the above address. That's the name of the Docker VM. Handy for human identification purposes.

If the above doesn't work for finding the BN-IP for the "default" VM you may have luck looking at what your router is seeing (see example below). Notice that "jakes-macbook" has a "2" annotation near the device icon. That means there are two clients associated with the icon. 192.168.1.24 is not the BN-IP for the "default" VM. The IP address will switch back and forth (at odd times). The other address, 192.168.1.93, is the BN-IP for the "default" VM.
enter image description here

The Rest of the Never-ending Story

Fire up the Odoo container then access it with Computer B at BN-IP address 192.168.1.93:8069 (for example). Great SUCCESS! Hopefully....

Troubleshooting

Use ping to try and figure out if the BN-IP for the "default" VM is active and go from there to make this method work. For a cleaner solution see the method regarding modifying Network Adapter 1. It is a much easier method to implement.

Involuntary answered 28/4, 2016 at 17:49 Comment(3)
Thank you. Second solution worked like a charm, and thank you for providing information about hard IP finding. I'm on windows so the provided link doesn't work, but my router managed to show me the ip.Skipp
Worth noting is to change the Adapter type to Intel PRO/1000 MT Desktop (82540EM). If you leave the default PCnet-FAST III (Am79C973) it won't work. See my commentWeird
Hello,do you know how to make bridged ip static from default vmNeptunian

© 2022 - 2024 — McMap. All rights reserved.