I’m in the process of dockerizing my playwright project. I’m a little confused as I’m new to docker. If anyone can provide insight it would be appreciated.
I’m a little hazy about copying my files. How would you copy your playwright.config file if you have to install playwright ? Would it get overwritten ?
I’m using the node playwright image as a starting point, setting my working directory and then copying all the files needed. I’m assuming I’d want to run my package.json file after that with npm install.
Then I’m a little lost after that point. I was reading the lamda test docs earlier for references
This thread is trying to answer question "How to dockerize a Playwright project and resolve issues encountered during the process?"
“` FROM node:16
FROM mcr.microsoft.com/playwright:v1.34.0-jammy
WORKDIR /app/
COPY node_modules /app/
COPY tests /app/
COPY test-documents/ /app/
COPY .env/ /app/
COPY config.ts/ /app/
COPY global.d.ts/ /app/
COPY package.json/ /app/
COPY UploadedDocs/ /app/
RUN apt-get update && apt-get -y install libnss3 libatk-bridge2.0-0 libdrm-dev libxkbcommon-dev libgbm-dev libasound-dev libatspi2.0-0 libxshmfence-dev
RUN npm install
“`
https://playwright.dev/docs/docker
docker run -it --rm -v "$(pwd)/":'/app' --ipc=host mcr.microsoft.com/playwright:v1.35.0-jammy /bin/bash
cd /app
npx playwright test my-test-for-google-com.spec.ts
so the benefit here is all the tools for video recording, chrome, are all pre installed in the image. The docs show how to integrate to various ci systems using a manual approach and using the image approach. When I first start reviewing a project I always look for the docker image so I can pre test before committing.
the image approach would work well for a system like artillery.io where their docs state you can use a playwright test and they will scale it to x nodes for performance testing. The assumption is you have a performance testing environment (url) - it is not hermetic as part of their scale out.
now problems with docker is "nested docker" . Say i need a hermetic server that my test brings up. The common way to build hermetic servers locally is using docker compose but if you are already running in an image you will need to look at how to support nested virtualization. So I only use docker configs like these to test the product and once I commit I install the tool.
this first command
docker run -it --rm -v "$(pwd)/":'/app' --ipc=host mcr.microsoft.com/playwright:v1.35.0-jammy /bin/bash
Is telling me its invalid i pulled the playwright image but i dont see an app in any directory
Related Ask AI answer for "What are the steps to containerize a Playwright project using Docker and how to troubleshoot common issues?".
Here's a quick guide on how to dockerize your Playwright project and troubleshoot any issues you might face.
First, create a Dockerfile for your project. This file is used to build a Docker image with all the necessary dependencies and configurations for your project.
FROM node:14
COPY . /app
WORKDIR /app
RUN npm install --production
If you run into memory usage issues or crashes when running Chromium inside the container, use the --ipc=host
flag when launching Chromium. This allows Chromium to share its inter-process communication (IPC) namespace with the host system and prevents out-of-memory errors.
If you face other issues like zombie processes or special treatment for processes with PID=1, consider using --init
flag or installing dumb-init in your container.
Once your Dockerfile is ready, build an image with this command:
docker build -t my-playwright-project .
After building the image, you can run a container based on that image using docker run
. Remember to expose any required ports and mount volumes if needed.
If you encounter specific issues during this process or need further assistance, please provide more details about the problems you are facing.
This guide provides a general guideline for dockerizing a Playwright project. The specific configurations and troubleshooting steps may vary depending on your project's requirements and the issues you encounter.
Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].