Skip to content

How To: Port Forwarding on VirtualBox

patocox edited this page Sep 22, 2014 · 3 revisions

Using the CoreOS Private IP

Beginning in Panamax Installer version 0.2.1, Panamax automatically creates a private IP for you CoreOS VM -- 10.0.0.200. You can use this to access your application when you have a host port assigned to your container. For example, if you have the following host to container port binding: 8080 : 80 / TCP, you can access your service using the private IP address: http://10.0.0.200:8080.

If you opted for Panamax to create an alias for the private IP during installation or reinstallation, you can access your application's services via that domain. For example: http://panamax.local:8080.

Port Forwarding

If your application has an endpoint that you need to be able to access outside of the container, you need a port exposed on the CoreOS host that points to the port in the container hosting the endpoint. For example, if your application runs an HTTP server on port 80, you need to bind a port from CoreOS to port 80 within Panamax. The following shows the host port, 8080, bound to the container port, 80.

CoreOS can now access the web app via port 8080; however, in order to reach that endpoint from your local machine, we need to make another hop from our local machine to the CoreOS port. To do this, we need to make a port forwarding rule in VirtualBox to port 8080.

This can be accomplished in two ways: 1) via the terminal windows of your local machine, or 2) via the VirtualBox GUI.

###Port Forwarding via the terminal window

On your local machine, open a terminal window and run the following command:

$ VBoxManage controlvm panamax-vm natpf1 rule1,tcp,,8997,,8080

This command invokes the VirutalBox command VirtualManage to add a port forwarding rule to the VM named, panamax-vm. The rule created is named rule1, the protocol is set to tcp and the port forwarding is set to 8997 from the local machine to 8080 to match the port on the CoreOS host.

NOTE: The empty values between the ports is intentional. Be sure to add the ,, around the local host port to ensure the mapping works correctly.

By browsing to http://localhost:8997, your browser is forwarded to port 8080 on the CoreOS host and then forwarded again to port 80 on the container to render the GUI. You can use any free port on your local machine to forward to the CoreOS host.

###Port Forwarding via the VirtualBox GUI The second method to set port forwarding is via the VirtualBox GUI. Follow these steps to enable port forwarding to your CoreOS host:

  1. Open the VirtualBox GUI on your local machine. Should be available in your Application directory.
  2. Find the panamax-vm in the list of virtual machines and select Settings from the top nav
  3. Click on the Network icon on the top nav

  1. Select Port Forwarding
  2. Click the Add rule icon on the top right and fill in your Host port, 8997, and your Guest port, 8080.

  1. Click OK and OK and the forward is set

By browsing to http://localhost:8997, your browser is forwarded to port 8080 on the CoreOS host and then forwarded again to port 80 on the container to render the GUI. You can use any free port on your local machine to forward to the CoreOS host.

Clone this wiki locally