How to launch host browser from script inside docker container?

Viewed 287

I am using Windows 10 with docker setup. I have the following test_browser.py script in ubuntu container which tries to launch web browser:

import webbrowser

result = webbrowser.open("http://localhost:7070")

print(result)

If I try to run the above script inside container, it fails to open the url and prints False since there is no browser inside container.

Testing script with CMD

Hence, I somehow want the script inside container to launch the url in host (windows) browser instead!

Fortunately, I have found a way to achieve it using VSCode: We can attach to the running docker container and run the python script in its terminal. It will launch my windows chrome browser. Notice True output as well!

Testing script with VSCode

Since it is possible, I am looking for a way to do it without involving VSCode. Maybe some docker commands which can make it happen?

0 Answers
Related