admin管理员组文章数量:1402350
I have a simple script that launches a chromium playwright browser instance. Running the script locally with --remote-debugging-port=9222
as an argument works fine, and visiting http://127.0.0.1:9222/json/version returns info about the browser instance in JSON format as expected. So far so good.
However, when I run the exact same script inside a docker container with a playwright server running (and -p 9222:9222
to port forward), and visit http://127.0.0.1:9222/json/version or http://localhost:9222/json/version there is nothing there. Any advice would be very appreciated.
This is my script.js file:
const { chromium } = require('playwright');
(async () => {
const browser = await chromium.launch({
headless: true,
args: [
'--remote-debugging-port=9222',
'--remote-debugging-address=0.0.0.0',
'--no-sandbox',
'--disable-gpu',
'--disable-software-rasterizer',
'--disable-dev-shm-usage',
'--disable-background-networking'
]
});
// Optionally, open a page
const page = await browser.newPage();
await page.goto(''); // example, you can visit any page you like
})();
Dockerfile:
# Use the Playwright base image
FROM mcr.microsoft/playwright:v1.50.0-noble
# Copy your script.js into the container
COPY script.js .
RUN npm install [email protected]
# Command to run your script.js when the container starts
CMD ["sh", "-c", "npx -y [email protected] run-server --port 3000 --host 0.0.0.0 & node script.js"]
package.json:
{
"dependencies": {
"playwright": "^1.50.0"
},
"scripts": {
"start": "node script.js"
}
}
I then build the image and run it with "docker run -p 3000:3000 -p 9222:9222 ".
版权声明:本文标题:Playwright remote debugging port 9222 inaccessible when running inside a docker container - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744299132a2599492.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论