'How to forward ports from GitPod-container to local machine when using JetBrains Gateway?

I use GitPod and JetBrains Gateway to develop my application. I run an application in a docker container inside GitPod-container. The container with application expose ports to handle HTTP requests. Is it possible to forward this port to port in my local machine using JetBrains Gateway?



Solution 1:[1]

Did you consider the following approach?

Assuming a docker container exposing 8080, in .gitpod.yml you would have something like:

tasks:
  - name: docker
    openMode: split-left
    command: docker build -t hello-world . && docker run -p 8080:80 hello-world
  1. Now, expose the port, again from your .gitpod.yml:
ports:
  - port: 8080
    onOpen: open-browser
    visibility: public
  1. Once the JetBrains IDE opens, go to the integrated terminal and run:
gp url 8080

You will be presented with the remote URL for the workspace, exposing the port 8080. The URL will look like: https://8080-****.ws-eu44xl.gitpod.io.

FYI, there is also an option to Connect via SSH to the workspace, if you find that useful. You find the SSH connection snippet, in the "More Actions" button in the workspace running-status page or when you explore the list of active workspaces (click on the three dots).

If it helps, I've created a sample repo to test this: https://github.com/andreafalzetti/gitpod-experiments-c

If you want to port-forward and open http://localhost:{PORT} locally, I think that is currently not supported by JetBrains Gateway.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Andrea Falzetti