Join our Discord Server
Ajeet Raina Ajeet Singh Raina is a former Docker Captain, Community Leader and Arm Ambassador. He is a founder of Collabnix blogging site and has authored more than 570+ blogs on Docker, Kubernetes and Cloud-Native Technology. He runs a community Slack of 8900+ members and discord server close to 2200+ members. You can follow him on Twitter(@ajeetsraina).

Running a Web Browser in a Docker container

1 min read

Are you still looking out for a solution that allows you to open multiple web browsers in Docker containers at the same time? Most people use Docker as a standard unit of software that packages up code and all its dependencies so that the application runs quickly and reliably from one computing environment to another. A Docker container image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries, and settings.

Today, all major cloud providers and leading open source serverless frameworks use Docker, and many are leveraging Docker for their container-native IaaS offerings. Docker makes development efficient and predictable. Docker takes away repetitive, mundane configuration tasks and is used throughout the development lifecycle for fast, easy, and portable application development – desktop and cloud. Docker’s comprehensive end-to-end platform includes UIs, CLIs, APIs, and security that are engineered to work together across the entire application delivery lifecycle.

Let us agree to the fact that browser testing can be a pain for the most seasoned testers, but it’s particularly challenging for newbies. In today’s world, an application behaves differently in different browsers, in different resolutions, and sometimes in different operating systems. To give new testers a running start, testing these web browsers in Docker containers can expedite their testing effort.

Under this blog, I will show you how to run Firefox web browser in Docker container. This has been tested on Docker Desktop for Mac.

Pre-requisite

  • Install Docker Desktop
  • Enable File Sharing under Docker Desktop > Preference as shown below:

The GUI of the application is accessed through a modern web browser (no installation or configuration needed on the client side) or via any VNC client.

Launch the Firefox docker container with the following command:

 % docker run -d \    
    --name=firefox \
    -p 5800:5800 \
    -v /Users/ajeetraina/datas:/config:rw \
    --shm-size 2g \
    jlesage/firefox
30220d1c22fa13ce24eb2ddaad7de88f67eefb8ce9388701aa5666795561b8eb

Open https://localhost:5800 and access the firefox over the browser.

You can check what’s happening in the backend by running the below CLI:

% docker logs -f 3022
The VNC desktop is:      30220d1c22fa:0
PORT=5900

******************************************************************************
Have you tried the x11vnc '-ncache' VNC client-side pixel caching feature yet?

The scheme stores pixel data offscreen on the VNC viewer side for faster
retrieval.  It should work with any VNC viewer.  Try it by running:

    x11vnc -ncache 10 ...

One can also add -ncache_cr for smooth 'copyrect' window motion.
More info: http://www.karlrunge.com/x11vnc/faq.html#faq-client-caching

Mozilla Firefox 84.0.2
01/05/2021 06:22:38 Got connection from client 127.0.0.1
01/05/2021 06:22:38   other clients:
01/05/2021 06:22:38 Got 'ws' WebSockets handshake
01/05/2021 06:22:38 Got protocol: binary

Click on “Dashboard” to see what percentage of resources this Docker container is consuming:

Click on the console sign just near to the stats to open browser.

You can also open terminal icon next to the browser option to enter into the firefox container shell:

ajeetraina@Ajeets-MacBook-Pro ~ % docker exec -it 30220d1c22fa13ce24eb2ddaad7de88f67eefb8ce9388701aa5666795561b8eb /bin/sh
/tmp # free -m
              total        used        free      shared  buff/cache   available
Mem:           1987        1365          82         218         538         359
Swap:          1023         475         548
/tmp # cat /etc/os-release
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.12.6
PRETTY_NAME="Alpine Linux v3.12"
HOME_URL="https://alpinelinux.org/"
BUG_REPORT_URL="https://bugs.alpinelinux.org/"
/tmp # 

Further References

Have Queries? Join https://launchpass.com/collabnix

Ajeet Raina Ajeet Singh Raina is a former Docker Captain, Community Leader and Arm Ambassador. He is a founder of Collabnix blogging site and has authored more than 570+ blogs on Docker, Kubernetes and Cloud-Native Technology. He runs a community Slack of 8900+ members and discord server close to 2200+ members. You can follow him on Twitter(@ajeetsraina).
Join our Discord Server
Index