Want to run multiple processes on a single container? That’s where Supervisord comes into play. Supervisord is a process management tool and it is easy to set up on top of Docker images.

Originally, I wanted to set up a VNC server on an Ubuntu-based image (Playwright). To that end, I had to run the following commands on the same container:

  1. Xvfb: display server
  2. x11vnc: VNC server
  3. fluxbox: window manager
  4. websockify: proxy to serve noVNC client

Since Docker’s entrypoint runs only one process I needed something that invokes and takes care of these 4 processes. This time, I chose Supervisord for that. All I had to do was create a configuration to run the commands above like this:

;# vnc.conf
[program:xvfb]
command = Xvfb %(ENV_DISPLAY) -screen 0 1024x768x16

[program:vncserver]
environment = PORT=5900
command = x11vnc -display %(ENV_DISPLAY) -forever -nopw -quiet -listen 0.0.0.0 -xkb

[program:fluxbox]
command = fluxbox

[program:novnc]
command = websockify --web=/usr/share/novnc/ 0.0.0.0:5901 0.0.0.0:5900

And place it under /etc/supervisor/conf.d/ so the supervisord can read it:

# Dockerfile
FROM mcr.microsoft.com/playwright:v1.27.0-focal

RUN apt update \
    && apt install -y --no-install-recommends xvfb fluxbox x11vnc novnc websockify supervisor \
    && apt clean

COPY vnc.conf /etc/supervisor/conf.d/vnc.conf

ENV DISPLAY=:1
CMD ["/usr/bin/supervisord", "--nodaemon", "--loglevel", "debug"]

Then the image will be ready to use VNC. Time to build and run.

docker build . -t playwright-with-vnc
docker run --rm -it --publish=5901:5901 --workdir=/work --volume=$PWD:/work playwright-with-vnc

Now the VNC client (noVNC) is available on http://localhost:5901/vnc.html. Yay!

See Also