K6 on Docker - Permission Denied

Hi,
I’ve tried getting k6 on Docker/Kubernetes, and I’ve modified the original docker image to include this GitHub - prometheus/statsd_exporter: StatsD to Prometheus metrics exporter and send output to the exporter, so now I have a running container from which I can run k6.
The problem is when I try to run a test using k6 run I get

level=error msg="stat .: permission denied"

The weird thing is I get this error even if I run

k6 run "path-that-does-not-exist"

which means this is related to k6, but since I can execute k6 this doesn’t seem like an ACL thing.
What am I missing? Any ideas?

Hi there,

the k6 Docker image runs as an unprivileged k6 user, and with your addition of statsd_exporter you might’ve reset some permissions to root or changed the working directory to one that the k6 user can’t read. Try fixing it with chmod or with the WORKDIR instruction. We might be able to help more if you share your Dockerfile, but in general this is not a Docker support forum. :slight_smile:

Though is there a particular reason you have to change the k6 Docker image or create a custom one at all? I think it would be simpler if you started the exporter as a separate container and sent it metrics with k6 run --out statsd.

FWIW, I don’t get a permission denied error with the official image:

> sudo docker run --rm -it loadimpact/k6 run path-that-does-not-exist

          /\      |‾‾|  /‾‾/  /‾/
     /\  /  \     |  |_/  /  / /
    /  \/    \    |      |  /  ‾‾\
   /          \   |  |‾\  \ | (_) |
  / __________ \  |__|  \__\ \___/ .io

WARN[0000] The moduleSpecifier "path-that-does-not-exist" has no scheme but we will try to resolve it as remote module. This will be deprecated in the future and all remote modules will need to explicitly use "https" as scheme.
ERRO[0000] The moduleSpecifier "path-that-does-not-exist" couldn't be found on local disk. Make sure that you've specified the right path to the file. If you're running k6 using the Docker image make sure you have mounted the local directory (-v /local/path/:/inside/docker/path) containing your script and modules so that they're accessible by k6 from inside of the container, see https://k6.io/docs/using-k6/modules#using-local-modules-with-docker. Additionally it was tried to be loaded as remote module by prepending "https://" to it, which also didn't work. Remote resolution error: "Get "https://path-that-does-not-exist": dial tcp: lookup path-that-does-not-exist on 172.16.1.1:53: no such host"

I’ve changed the working directory inside my dockerfile and looks like that’s ruined it. Thank you very much for your help!
As for your question, I’m trying to get this on Kubernetes. The k6 container exits immediately and apparently Kubernetes pods don’t like that, so that seemed like a nice solution since I need the exporter in any case.

On kubernetes? In that case, I would suggest you to revisit the idea of using the original docker image and run statsd-exporter in a separate container. You can use the kubernetes Job resource available in batch/v1 for running k6, as it’s a one-off, and keep the statsd-exporter standalone.

Modifying the image is likely to give you headaches at some point down the road.