0

I have dockerized two services:

  • web frontend(containing the gui in angular accessed on port 3000)
  • backend(that has puppeteer dependency for extracting data from a web page accessed on port 8111)

Below is the simplified version dockerfile for the backend:

FROM private/node:v10.22.1
# Dependencies needed for backend (removed for simplicity)
RUN apt-get update
RUN apt-get install -y ...

USER root:root

COPY ./backend /node/backend

WORKDIR /node/backend
RUN npm install --unsafe

CMD npm start

EXPOSE 8011

They communicate with each other with sock.io.

The backend has two modes of running the extraction(headless and headful). The headless extraction works successfully with these dockerized services.

The headful extraction when running the backend locally it pops up web browser containing the page that is being processed. When headful extraction is enabled on the dockerized backend that it fails because the container doesn't have GUI.

To fix the headful extraction on the backend I have modified the docker file below:

FROM private/node:v10.22.1
# Dependencies needed for backend (removed for simplicity)
RUN apt-get update
RUN apt-get install -y ...

# Adding dependecies that are needed to create fake display in container
RUN apt-get update &&\
apt-get install -yq gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 \
libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 \
libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 \
libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 \
ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget \
xvfb x11vnc x11-xkb-utils xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic x11-apps

USER root:root

COPY ./backend /node/backend

WORKDIR /node/backend
RUN npm install --unsafe

# Creating display
ENV DISPLAY :99

# CMD npm start
CMD Xvfb :99 -screen 0 1024x768x16 & npm start

EXPOSE 8011

And I am running both containers without network isolation like below:

docker run --network host web
docker run --network host --env="DISPLAY" backend 

After these changes, the headful extraction works successfully but the browser windows don't pop up.

  1. Why isn't the browser windows popping up?
  2. This should be able to work also for the Windows host machine where is not possible to remove network isolation. Is it possible to achieve popping a browser from the container to the host machine without removing the network isolation?

Kind Regards, Rando.

P.S

I trying to achieve to run the GUI of the web browser that is started inside the container in the host where the host is Windows. I need to know if it is possible to achieve this where the container is Linux and the host is Windows and the removal of network isolation(net=host) is not possible.

Rando Shtishi
  • 1,222
  • 1
  • 21
  • 31

1 Answers1

2
  1. The browser window isn't popping up because xvfb is a Virtual Frame Buffer. That is, it is emulating a screen inside the container. If you want to see the browser window inside the container, you can use x11vnc which will allow you to see what's going on inside the containers display. This question has great answers on how to achieve that.

Step-by-Step Guide on how to vnc into a docker container running xvfb.

  1. No, that's not going to be possible- what's the point of running this in a container if you want to use the browser on the host machine?
Nico Mee
  • 869
  • 5
  • 6
  • Thank you for your answer. Is it possible to see a browser window inside the container with x11vnc where the container is Linux and the host is Windows? – Rando Shtishi Aug 13 '21 at 14:25
  • I need to make it work for both Linux and Windows hosts. And with Windows as docker hosts, it is not possible to remove network isolation. It is required for x11vc to remove network isolation? – Rando Shtishi Aug 13 '21 at 14:27
  • 1
    Absolutely! You can use any vnc client on the host machine (windows) to do that. Personally, I like [TightVNC](https://www.tightvnc.com/download.php). – Nico Mee Aug 13 '21 at 14:28
  • Thank you a lot! I am accepting the answer and I will try after I returned from vacation. – Rando Shtishi Aug 13 '21 at 14:30
  • 1
    Thanks! I've added a good step-by-step guide on how to vnc into the container to my answer. – Nico Mee Aug 13 '21 at 14:39