Dockerfile
Let's start with the Dockerfile.
Dockerfile
The Playwright Dockerfile is given below.
#Baseimage is nodeFROM node:10COPY . .#Installing all the dependencies needed by PlaywrightRUN apt-get update &&\apt-get -y install libnss3 &&\apt-get -y install libasound2 &&\apt-get -y install libatspi2.0-0 &&\apt-get -y install libdrm2 &&\apt-get -y install libgbm1 && \apt-get -y install libgtk-3-0 && \apt-get -y install libxkbcommon-x11-0 && \# Move to the directory and install all the dependencies listed in Package.jsonRUN cd playwright-master && \npm install
Base Image
Playwright is a Javascript-based, Node.js library.
That’s why the base image contains the 10th version of the Node in line 2
.
Importing code to the Docker image
In line 4
, we are importing code from our directory to Docker image.
Dependencies for Playwright
In order to run Playwright locally or on the educative platform, it is essential to install all the libraries given below. Otherwise, it throws the error of missing libraries
.
RUN apt-get update &&\
apt-get -y install libnss3 &&\
apt-get -y install libasound2 &&\
apt-get -y install libatspi2.0-0 &&\
apt-get -y install libdrm2 &&\
apt-get -y install libgbm1 && \
apt-get -y install libgtk-3-0 && \
apt-get -y install libxkbcommon-x11-0 && \
Playwright Boilerplate Directory
In line 17
, we move into the directory of Playwright boilerplate and run npm install
to download all the node modules listed in the package.json
file.
Our Dockerfile is ready!!
Building a Tar File
Let’s build a tar file of the Docker image created. The Dockerfile and the app folder should be present in the same folder on your machine. Go to that folder in the terminal and run this command.
tar -czvf playwright-educative.tar.gz Dockerfile playwright-master
playwright-master is the name of folder that contains the playwright boilerplatecode. You can name it according to your choice.
After running this command, a tar file will be created in the same folder.
Now, we only have to upload this file on the Educative platform. You can have a look at this to know how to upload a Dockerfile on educative.
Great work, now let’s head over to the next lesson to start playing with Playwright.