Rayrun
← Back to Discord Forum

dockerizing playwright project

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?"

13 replies

“` FROM node:16

offical node playwright image

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

“`

This is my Dockerfile

Whoops sorry for formatting , I’m on mobile 😅

leblancmeneses

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.

@leblancmeneses: 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

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

docker run -it --rm --ipc=host mcr.microsoft.com/playwright:v1.35.0-jammy /bin/bash

i used this command , maybe i misread what you said

leblancmeneses

run the first command inside the folder created using npm init playwright@latest

leblancmeneses

this will mount pwd, present working directory, into the container as /app

sorry a little confusing, you want me to run this npm init playwright@latest at the root level in the playwright image?

leblancmeneses

hopefully this helps you

Very helpful ! Thank you ❤️

Answer

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.

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

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].