Hello, what I need is to run docker build & run through Dockerfile, but I found that the only possible way to run docker commands is inside docker-compose file. My Dockerfile looks like this:
the commands that I need to run are: docker build -t grafana/k6-for-sql:latest . docker run --rm -i grafana/k6-for-sql run - <tests/test1.js --insecure-skip-tls-verify
How the docker-compose should look like in order to run properly?
I haven’t tested your concrete example. I usually go by the Dockerfile in the extension repo. In your case I would start with xk6-sql/Dockerfile at master · grafana/xk6-sql · GitHub, with --with github.com/grafana/xk6-sql instead of --with github.com/grafana/xk6-sql=.
You cannot run a k6 instance with extensions in docker this way.
This topic is in the realm of docker-knowledge more than k6. and you should be able to achieve this using the docker documentation and the links I shared in my first post. You have to build a docker image that has the extension/s you want to use, and if you want execute later with docker-compose, that is doable. But you need to build the image before, if it does not exist in a docker registry. And that you cannot do in the same docker compose.
For further reference, I’ll detail what you can do to run a k6 with the sql extension.
Create a script, e.g. script.js. In my example I simply import the module (import sql from 'k6/x/sql';), and don’t connect to any database. You can find different sql examples in xk6-sql/examples at master · grafana/xk6-sql · GitHub.
import http from 'k6/http';
import { sleep } from 'k6';
import sql from 'k6/x/sql';
export default function () {
http.get('https://test.k6.io');
sleep(1);
}
You can always check that the image has the right extensions by running docker-compose run --rm -T k6 version. In my case the output includes the extension github.com/grafana/xk6-sql as expected: