-
Notifications
You must be signed in to change notification settings - Fork 62
Description
I don't know who will need this (maybe even my future self), but I've been running everything in devcontainers, and only stumbled a little in setting things up for this one workshop (the others all ran fine).
The first test passed, so I believe the rest should also work, so I'm sharing what I found out to make this work.
This setup uses a container for the workshop and another for the playwright's "remote server" (on the same machine).
Do checkout the playwright docs: https://playwright.dev/docs/docker#remote-connection
In the workshop terminal
PW_TEST_CONNECT_WS_ENDPOINT=ws://$(ip route | grep default | awk '{print $3}'):3000/ npm run test:e2e:dev -- --ui-port=9292 --ui-host=0.0.0.0Why not "docker.host.internal"?
PW_TEST_CONNECT_WS_ENDPOINT is from the docs.
Apparently, it refuses to connect. Using network=host is another option, and it is probably even easier (just pass it to devcontainers runArgs, then use localhost).
But this one works, getting the IP from the route, which is the "localhost" IP as seen from the container.
UI port/host
Without it, it fails. It searches for the playwright dependencies inside the container, but even without them, by passing those args, it will open the UI in a new page and work there.
In the Host Machine
docker run --network=host --rm --init -it --workdir /home/pwuser --user pwuser mcr.microsoft.com/playwright:v1.47.0-noble /bin/sh -c "npx -y playwright@1.47.0 run-server --port 3000 --host 0.0.0.0"The command is from the docs. The only thing to pay attention to is the version being used (1.47): the workshop version should match the one to run the server (I'm also matching the server/docker to be sure).
If you use an unsupported version, it will complain about version mismatch; in which case, just adjust the versions.
For this one, I'm using network=host because the scripts would most likely overwrite the config. But since both are in Docker, you could pass the add-host flag and use whatever name you passed there.
The docs example is add-host=hostmachine:host-gateway, so in the tests, you would use hostmachine.