Skip to content

Fails to spawn browser inside my Docker container app #2140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
MutarIO opened this issue Feb 14, 2025 · 5 comments
Open

Fails to spawn browser inside my Docker container app #2140

MutarIO opened this issue Feb 14, 2025 · 5 comments

Comments

@MutarIO
Copy link

MutarIO commented Feb 14, 2025

Hello guys,

I have a Docker container app in which I am trying to utilize nodriver in a python script.
However, for some reason it will never start properly.

When I try to spawn a browser (using the no_sandbox=True parameter inside my start function) I get the following error:

`(venv) root@cdee75c0f2bd:/var/www/python# python scraper/nodriver_scraper.py "https://example.com" "body"
Error:
---------------------
Failed to connect to browser
---------------------
One of the causes could be when you are running as root.
In that case you need to pass no_sandbox=True

Traceback: Traceback (most recent call last):
File "/var/www/python/scraper/nodriver_scraper.py", line 12, in scrape
driver = await uc.start(sandbox=False, headless=False)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/var/www/python/venv/lib/python3.11/site-packages/nodriver/core/util.py", line 95, in start
return await Browser.create(config)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/var/www/python/venv/lib/python3.11/site-packages/nodriver/core/browser.py", line 90, in create
await instance.start()
File "/var/www/python/venv/lib/python3.11/site-packages/nodriver/core/browser.py", line 351, in start
raise Exception(
Exception:
---------------------
Failed to connect to browser
---------------------
One of the causes could be when you are running as root.
In that case you need to pass no_sandbox=True

{"status": "error", "error": "\n ---------------------\n Failed to connect to browser\n ---------------------\n One of the causes could be when you are running as root.\n In that case you need to pass no_sandbox=True \n ", "traceback": "Traceback (most recent call last):\n File "/var/www/python/scraper/nodriver_scraper.py", line 12, in scrape\n driver = await uc.start(sandbox=False, headless=False)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File "/var/www/python/venv/lib/python3.11/site-packages/nodriver/core/util.py", line 95, in start\n return await Browser.create(config)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File "/var/www/python/venv/lib/python3.11/site-packages/nodriver/core/browser.py", line 90, in create\n await instance.start()\n File "/var/www/python/venv/lib/python3.11/site-packages/nodriver/core/browser.py", line 351, in start\n raise Exception(\nException: \n ---------------------\n Failed to connect to browser\n ---------------------\n One of the causes could be when you are running as root.\n In that case you need to pass no_sandbox=True \n \n"}`

I am already running with no_sandbox=True but this does not help.

If anyone knows a fix, please let me know!

@MutarIO
Copy link
Author

MutarIO commented Feb 14, 2025

I got everything working with Symfony Panther which also uses the same binary so the installation of Chromium inside my container is not the issue here. I am using the PHP-FPM base image.

@Altimis
Copy link

Altimis commented Feb 24, 2025

Same issue here ..
I even tried to run the docker container with a non-root user

@ultrafunkamsterdam
Copy link
Owner

Since when are Docker containers designed to run Gui apps?

Without hacks you can't easily just start a browser

@MutarIO
Copy link
Author

MutarIO commented Feb 24, 2025

Since when are Docker containers designed to run Gui apps?

Without hacks you can't easily just start a browser

Headless browser for dynamic webscraping is widely used. You need to install some dependencies but you can do it perfectly fine, headless or not.

@Altimis
Copy link

Altimis commented Feb 28, 2025

Any update about this issue please ? It was working fine before but starting from last week the start() method started throwing this error :

0|  |                 ---------------------
0|  |                 Failed to connect to browser
0|  |                 ---------------------
0|  |                 One of the causes could be when you are running as root.
0|  |                 In that case you need to pass no_sandbox=True 

I've tried setting sanbox to false, changing user to non-root user, using new user_data_dir, --disable-dev-shm-usage and plenty of other workarounds, but none of them is working.

IS this related to Nodriver or the browser itself ??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants