"GoError: launching browser: Missing X server " when running headless: false through docker

I am trying to execute xk6 test using docker with headless mode false, my OS is Windows 10 Pro , I run the last example test on Observing "GoError: launching browser: exec: no command while running browser tests on docker
It worked fine with “headless: true” , but I got error when changing to false

time="2023-01-25T09:57:51Z" level=error msg="GoError: launching browser: Missing X server or $DISPLAY\n\tat reflect.methodValueCall (native)\n\tat file:///-:9:34(8)\n\tat native\n" executor=per-vu-iterations scenario=default source=stacktrace

JS script

import { sleep } from 'k6';

import { chromium } from 'k6/x/browser';
import { Counter, Rate, Trend } from "k6/metrics";

//let  timeToFirstByte = new Trend("time_to_first_byte", true);

export default function () {
  const browser = chromium.launch({
    headless: false,  // false if you wish to view the browser
    slowMo: '500ms',

  const context = browser.newContext();
  const page = context.newPage();
  page.goto('https://test.k6.io/').then(() => {
    const elem = page.$('a[href="/my_messages.php"]');
    page.screenshot({ path: `example-chromium.png` });
    page.screenshot({ path: `example-chromium1.png` });
  }).finally(() => {

Docker file

FROM golang:1.19-bullseye as builder

RUN go install -trimpath go.k6.io/xk6/cmd/xk6@latest

RUN  xk6 build --output "/tmp/k6" --with github.com/grafana/xk6-browser

FROM debian:bullseye

RUN apt-get update && \
    apt-get install -y chromium

COPY --from=builder /tmp/k6 /usr/bin/k6



Docker compose yml:

version: '3.4'

    build: .

Could you please help me with this error ?

Hi @vsanabria,

Welcome to the forum.

The issue is that the docker image is itself headless, and the error message is telling us to install the missing package:

I don’t have a Windows laptop to hand, but I have in the past been able to run headful tests on Windows 11 using WSL2 + Docker.

You could also try this: Run GUI app in linux docker container on windows host - DEV Community. I’ve not tried to work with this solution.

Let us know if either of the solutions help.