Before we begin, make sure you have the following installed:
First, let's create a Dockerfile in the root of your project. This file will contain instructions for building our container image.
This Dockerfile uses the official Playwright image as the base image, sets the working directory to /app, installs the dependencies, and finally starts the application.
Alternatively, you can install the required dependencies on your own. In the example below, we are using the node alpine image which is a lightweight version of the Node.js runtime environment available for Docker. The alpine image is based on Alpine Linux designed for containers. This image is perfect for applications that require minimal overhead for their runtime environments, as it has a small footprint with a minimal set of tools installed.
Next, let's build the Docker image using the following command:
If you’re using a M1 mac and planning to deploy on amd 64 based architecture (Amazon linux in our case)
You can build the image using the following command
Replace your-image-name with the name you want to give your container image.
Now we'll push our Docker image to Amazon Elastic Container Registry (ECR) so that we can deploy it to ECS.
First, create a new repository in ECR:
Replace your-repo-name with the name you want to give your ECR repository.
Next, log in to ECR using the AWS CLI:
Replace your-region with your AWS region, and your-account-id with your AWS account ID.
Now, tag your Docker image with the ECR repository URI:
Finally, push the Docker image to ECR:
Now that our Docker image is in ECR, we can deploy it to ECS.
First, create an ECS cluster:
Replace your-cluster-name with the name you want to give your ECS cluster.
Next, create a task definition for your container. Save the following JSON to a file called task-definition.json:
Replace your-task-definition-name with the name you want to give your task definition, your-container-name with the name you want to give your container, your-account-id with your AWS account ID, and your-region with your AWS region.
Now, register the task definition with ECS:
Finally, create a service to run your container:
Replace your-cluster-name with the name of your ECS cluster, your-service-name with the name you want to give your service, your-task-definition-name with the name of your task definition, your-subnet-id with the ID of your VPC subnet, and your-security-group-id with the ID of your security group.
Your Playwright container should now be running in ECS. You can view the logs and monitor the status of your container using the AWS Management Console.
In this tutorial, we've learned how to deploy a Playwright container using Docker in AWS. This allows us to run our Playwright tests in a scalable, cloud-based environment. By deploying our container to Amazon ECS, we can easily scale our tests to handle increased load and take advantage of AWS's robust infrastructure.
Handling something as resource-intensive as playwright can be painful. Try screenshotapi instead, which is a reliable solution for taking screenshots or generating PDFs of any website in seconds.
©2025 ScreenshotAPI. All Rights Reserved.