Skip to content

Commit

Permalink
Include X11 VNC server.
Browse files Browse the repository at this point in the history
  • Loading branch information
vaibhavpandeyvpz committed Sep 29, 2023
1 parent 44f4c0f commit b9a661c
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 12 deletions.
15 changes: 10 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
FROM debian:bookworm-slim

ENV DEBIAN_FRONTEND noninteractive

RUN apt-get update && \
apt-get install -y gnupg unzip wget && \
rm -rf /var/lib/apt/lists/* /var/cache/apt/*
Expand Down Expand Up @@ -28,19 +30,22 @@ RUN CHROME_VERSION=$(google-chrome --version | sed -E "s/.* ([0-9]+)(\.[0-9]+){3
chmod 755 /opt/chromedriver/chromedriver-$CHROMEDRIVER_VERSION && \
ln -fs /opt/chromedriver/chromedriver-$CHROMEDRIVER_VERSION /usr/bin/chromedriver

RUN apt-get update && \
apt-get install -y fluxbox pulseaudio x11vnc && \
rm -rf /var/lib/apt/lists/* /var/cache/apt/*

RUN groupadd -r chrome && \
useradd -rm -g chrome -G audio,pulse-access,video chrome && \
usermod -s /bin/bash chrome

RUN apt-get update && \
apt-get install -y supervisor && \
rm -rf /var/lib/apt/lists/* /var/cache/apt/*

COPY supervisor.conf /etc/supervisor/supervisor.conf

RUN groupadd -r chrome && \
useradd -rm -g chrome -G audio,video chrome

USER chrome

WORKDIR /home/chrome

ENV DISPLAY :99

CMD ["sh", "-c", "supervisord -c /etc/supervisor/supervisor.conf --logfile /dev/null --pidfile /dev/null"]
32 changes: 28 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# chromedock

[Docker](https://www.docker.com) image with latest [Chrome](https://www.google.com/chrome/) + [chromedriver](https://googlechromelabs.github.io/chrome-for-testing/) for use in local development (or maybe elsewhere but not recommended).
[Docker](https://www.docker.com) image with latest [Chrome](https://www.google.com/chrome/), [chromedriver](https://googlechromelabs.github.io/chrome-for-testing/) and a [VNC](https://en.wikipedia.org/wiki/Virtual_Network_Computing) server for use in local development (or maybe elsewhere but not recommended).

![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/syncloudsoftech/chromedock/publish.yml?branch=main)
![Docker Pulls](https://img.shields.io/docker/pulls/syncloudsoftech/chromedock)
Expand All @@ -11,19 +11,42 @@ To launch a container from this image, you must have [Docker](https://www.docker
If already, run the below command:

```shell
$ docker run -d --name chromedock -p 4444:4444 syncloudsoftech/chromedock
$ docker run -d --name chromedock -p 4444:4444 -p 5900:5900 syncloudsoftech/chromedock
```

To start/stop the (named) container at a later point in time, use below commnads:

```
```shell
# start "chromedock" named container
$ docker start chromedock

# stop "chromedock" named container
$ docker stop chromedock
```

You can also connect to port `5900` using any [VNC](https://en.wikipedia.org/wiki/Virtual_Network_Computing) client e.g., [RealVNC Viewer](https://www.realvnc.com/en/connect/download/viewer/) to interact with running [Chrome](https://www.google.com/chrome/) instances.

Further to use in automation, you can specify the [chromedriver](https://googlechromelabs.github.io/chrome-for-testing/) server address shown as below:

```js
const { Builder, By, Key, until } = require('selenium-webdriver');

(async function example() {
const driver = await new Builder()
.forBrowser('chrome')
.usingServer('http://<container_hostname_or_ip>:4444')
.build();
try {
await driver.get('http://www.google.com/ncr');
await driver.findElement(By.name('q')).sendKeys('Syncloud Softech', Key.RETURN);
await driver.wait(until.titleIs('Syncloud Softech - Google Search'), 1000);
} finally {
await driver.quit();
}
})();

```

### docker-compose.yml

To include this container as a service in your existing `docker-compose.yml` setup, use below definition:
Expand All @@ -36,6 +59,7 @@ services:
image: syncloudsoftech/chromedock
ports:
- "4444:4444"
- "5900:5900"
```
## Development
Expand All @@ -50,7 +74,7 @@ $ docker build -t chromedock .
Run the locally built container as follows:

```shell
$ docker run -it -p 4444:4444 chromedock
$ docker run --rm -it -p 4444:4444 -p 5900:5900 chromedock
```

## License
Expand Down
25 changes: 22 additions & 3 deletions supervisor.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,33 @@
nodaemon=true

[program:chromedriver]
autorestart=true
command=/usr/bin/chromedriver --allowed-ips= --allowed-origins=* --port=4444
process_name=%(program_name)s
environment=DISPLAY=":99"
priority=300
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
user=chrome

[program:fluxbox]
autorestart=true
command=/usr/bin/fluxbox
environment=DISPLAY=":99"
user=chrome
priority=200

[program:xvfb]
command=/usr/bin/Xvfb :99 -ac -screen 0 1280x720x16 -nolisten tcp
process_name=%(program_name)s
autorestart=true
command=/usr/bin/Xvfb :99 -ac +extension RANDR -nolisten tcp -screen 0 1280x720x24
priority=100
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
user=chrome

[program:x11vnc]
autorestart=true
command=/usr/bin/x11vnc -display :99 -nopw -wait 5 -forever -xrandr
priority=400
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
user=chrome

0 comments on commit b9a661c

Please sign in to comment.