Firefox Docker



Dockerfile.bionic and Dockerfile.focal can be used to run Playwright scripts in Docker environments. These images includes all the dependencies needed to run browsers in a Docker container, and also include the browsers themselves.

Usage#

This image is published on Docker Hub.

Pull the image#

Oct 04, 2020 Download and Install Docker from the Synology Package Center. Open Docker and click on the Registry. Search for haugene/transmission-openvpn, click Download. Create the DNS config file ‘resolv.conf’, open a text editor and type the name server of your choosing. I’m using the name servers provided by Private Internet Access. Docker run -it -e DISPLAY -net=host jberkus/firefox This should bring up Firefox in a window on your desktop, under a profile and cache which exists only in the container. If you want to always dispose of this Firefox without saving anything, add an -rm flag to the above.

Run the image#

By default, the Docker image will use the root user to run the browsers. This will disable the Chromium sandbox which is not available with root. If you run trusted code (e.g. End-to-end tests) and want to avoid the hassle of managing separate user then the root user may be fine. For web scraping or crawling, we recommend to create a separate user inside the Docker container and use the seccomp profile.

End-to-end tests#

On trusted websites, you can avoid creating a separate user and use root for it since you trust the code which will run on the browsers.

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

Crawling and scraping#

On untrusted websites, it's recommended to use a separate user for launching the browsers in combination with the seccomp profile. Inside the container or if you are using the Docker image as a base image you have to use adduser for it.

$ docker run -it --rm --ipc=host --user pwuser --security-opt seccomp=seccomp_profile.json mcr.microsoft.com/playwright:bionic /bin/bash
Firefox Docker

seccomp_profile.json is needed to run Chromium with sandbox. This is a default Docker seccomp profile with extra user namespace cloning permissions:

{
'names':[
'setns',
],
'args':[],
'excludes':{}
]

Using --ipc=host is recommended when using Chrome (Docker docs). Chrome can run out of memory without this flag.

Using on CI#

See our Continuous Integration guides for sample configs.

Image tags#

See all available image tags.

Development#

Build the image#

Use //utils/docker/build.sh to build the image.

$ ./utils/docker/build.sh bionic playwright:localbuild-bionic

The image will be tagged as playwright:localbuild-bionic and could be run as:

$ docker run --rm -it playwright:localbuild /bin/bash

Push#

Docker images are published automatically by GitHub Actions. We currently publish the following images:

  • mcr.microsoft.com/playwright:next - tip-of-tree image version.
  • mcr.microsoft.com/playwright:bionic - last Playwright release docker image.
  • mcr.microsoft.com/playwright:sha-XXXXXXX - docker image for every commit that changed docker files or browsers, marked with a short sha (first 7 digits of the SHA commit).

Status of push to MCR can be verified here (internal link).

Base images#

Ubuntu 20#

mcr.microsoft.com/playwright:focal is based on Ubuntu 20.04 LTS (Focal Fossa).

Ubuntu 18#

mcr.microsoft.com/playwright:bionic is based on Ubuntu 18.04 LTS (Bionic Beaver).

Alpine#

Browser builds for Firefox and WebKit are built for the glibc library. Alpine Linux and other distributions that are based on the musl standard library are not supported.

  • Related Questions & Answers
  • Selected Reading
DockerOperating SystemOpen Source

After you have installed docker on your linux machine, the next step is to create an image and run a container. You need to create a base image of an OS distribution and after that you can add and modify the base image by installing packages and dependencies and committing the changes to it.

In this article, we will show you how to create an ubuntu base image and on top of that create intermediate image layers by adding packages in it and keep committing the changes. We will update the ubuntu base image, install 3 packages - vim editor, firefox and python 3.

Note that we can do this using two ways - either we mention all the commands inside a dockerfile and build the image all at once or we can do it step by step and keep committing the changes through CLI. We will discuss both the methods here.

Method 1. Step by Step using CLI.

  • Open a terminal and run the following command. Note that if you are not the root user, you need to add sudo before all the commands.

Firefox Docker Hub

This will check if an ubuntu image exists locally or not. If it does not exist, it will display “Unable to find image 'ubuntu:latest' locally” message and start pulling it from docker hub. After pulling the image, it will run the apt update command.

Firefox Dockerfile

  • We will now install a vim editor inside the container. For that, we will run the bash of the ubuntu image.

This will open an interactive ubuntu bash. Inside the bash, type the following commands one by one to install the packages.

The first command runs an update. It then installs vim editor, firefox and some dependencies for python 3. Then it adds the official python 3 repository and installs python 3.7 and then exits the bash.

You can check the version of python using the following command.

  • After exiting the bash, you need to commit the changes. Find out the container ID using the following command.

Copy the container ID and paste in the following command.

  • You can check that the new ubuntu image with the specified name and installed packages has been created using the following command.

Method 2. By creating a dockerfile

  • Create a file name dockerfile and place the following commands in it.

  • Build the image using the following command.

Docker Browser Container

This command builds the docker image using the dockerfile.

Firefox Docker Container

Run the docker image using the following command.

Firefox In Docker

To conclude, the better method to create an image and install packages is by creating a dockerfile with the appropriate commands because it will help you to keep track of the changes that you make and the packages that you install and gives a better clarity of the whole project.