My Docker configuration:
FROM python:3.11
WORKDIR /app
COPY /app .
RUN pip install --upgrade pip && \
pip install --no-cache-dir -r requirements.txt && \
rm requirements.txt
EXPOSE 8000
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
When I run inside in Docker container:
>>> webbrowser.open('https://stackoverflow.com/')
False
>>> webbrowser._browsers.items()
dict_items([])
When I try locally (MacOS):
>>> webbrowser.open('https://stackoverflow.com/')
True
>>> webbrowser._browsers.items()
dict_items([('macosx', [None, <webbrowser.MacOSXOSAScript object at 0x109b965d0>]), ('chrome', [None, <webbrowser.MacOSXOSAScript object at 0x109ee3b50>]), ('firefox', [None, <webbrowser.MacOSXOSAScript object at 0x109ee3b90>]), ('safari', [None, <webbrowser.MacOSXOSAScript object at 0x109ee3c10>])])
I tried installing the browser, but the result remained the same.
>>> webbrowser.get('chrome')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.11/webbrowser.py", line 66, in get
raise Error("could not locate runnable browser")
webbrowser.Error: could not locate runnable browser
Your container does not have a webbrowser installed so the python class can't find any.
You can try this in dockerfile to get chrome installed on the container
How to install Google chrome in a docker container