Can't access Playwright Chromium's remote debugging port in Docker

I’m having trouble with remote debugging in a Docker container. My Playwright script works fine locally, but not in Docker. I’ve set the remote debugging port to 9222, but can’t access it from outside the container.

Here’s what I’ve tried:

  • Added ‘–remote-debugging-address=0.0.0.0’ to the browser arguments
  • Mapped the port with -p 9222:9222 in Docker

When I check the container, I see:

tcp  0  0 127.0.0.1:9222  0.0.0.0:*  LISTEN  90/headless_shell

It looks like the port is bound to 127.0.0.1 instead of 0.0.0.0. How can I fix this? I’m out of ideas and could really use some help!

I faced a similar problem with Docker and Playwright. I discovered that the issue was that the browser wasn’t binding to all interfaces. In my case, I revised the launch options to add the flags ‘–remote-debugging-address=0.0.0.0’ and ‘–remote-debugging-port=9222’. After modifying the Dockerfile to expose port 9222 and running the container with ‘docker run -p 9222:9222’, the remote debugging worked as expected. Also, checking for firewall or network restrictions helped resolve the problem.

I’ve encountered this issue before. One solution that worked for me was modifying the Dockerfile to use the --cap-add=SYS_ADMIN flag when running the container. This grants additional privileges that Chromium needs for proper operation in a containerized environment. Additionally, ensure you’re using the latest version of Playwright, as older versions had some compatibility issues with Docker. If these steps don’t resolve the problem, you might want to check if there are any conflicts with other processes using port 9222 within the container. Running netstat -tulpn inside the container can help identify such conflicts.

hey, i had this issue too. try adding ‘–no-sandbox’ to ur browser args. it worked 4 me. also, make sure ur not using ‘headless: new’ in playwright config. switch to ‘headless: true’ instead. these tweaks might help ur docker setup. good luck!