I recently wanted to use the clipboard feature of Linux in a Docker container.

However, to use it, I needed a X server.

I found Xvfb, which is X server with a virtual framebuffer, i.e. an X server that displays only in memory and doesn’t connect to any hardware. You don’t need to run any client you don’t want in your Docker container, and in particular no desktop environment or window manager.

Indeed, the only thing you need is to install Xvfb.

Once it’s done, use this command as the main command (or entrypoint, whatever suits you) of your Docker container:

Xvfb :1 -screen 0 1x1x8 &

For example, if you use docker-compose:

version: '3'
    # ...
    command: [ "Xvfb", ":1" , "-screen", "0", "1x1x8" ]
    # ...