Running xk6 image on docker

Hi Team,

I build a custome xk6 docker image with xk6-output-prometheus-remote with the below commands on my docker file

FROM golang:1.19-alpine as builder


ADD . .

RUN apk --no-cache add build-base git

RUN go install

RUN CGO_ENABLED=0 xk6 build \ –with GitHub - grafana/xk6-output-prometheus-remote: K6 extension for Prometheus remote write \ –output /tmp/k6

FROM alpine:3.16
RUN apk add --no-cache ca-certificates \ && adduser -D -u 12345 -g 12345 k6

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

WORKDIR /home/k6

ADD ./test-scripts/simple.js /home/k6/


While running a test through the docker-compose up command

command: run -o xk6-prometheus-rw /home/k6/simple.js

Getting an error

could not create the ‘xk6-prometheus-rw’ output: parse environment variables options failed

But running with

command: run /home/k6/simple.js

The test runs fine, but no data push to Prometheus.

Guide me.

Hi @Gerard

I was testing with the docker-compose file provided as an example in the xk6-output-prometheus-remote extension and that seems to work well on my lab.

From the error you shared it seems that it fails to read some environment variables, which are probably defined in the docker compose file you use. Can you share your (sanitized) docker-compose file, so I can have a look and reproduce the issue locally? The concrete command you use to run the test will also help (e.g. docker-compose run --rm -T k6 run -<samples/test.js --tag testid=lab-1).


1 Like