I am having issue running k6 in detached mode.
docker run -i loadimpact/k6 run -<~/k6/script.js works fine:
/\ |‾‾| /‾‾/ /‾/
/\ / \ | |_/ / / /
/ \/ \ | | / ‾‾\
/ \ | |‾\ \ | (_) |
/ __________ \ |__| \__\ \___/ .io
time="2019-05-31T05:36:09Z" level=warning msg="Specifying infinite duration in this way is deprecated and won't be supported in the future k6 versions"
execution: local--------------------------------------------------] servertor
output: -
script: -
duration: -, iterations: -
vus: 1, max: 1
time="2019-05-31T05:36:10Z" level=info msg=Running i=1 t=872.119457ms starting
Adding the -d flag seems to make it fail after printing the logo:
$ docker run -d -i loadimpact/k6 run -<~/k6/script.js
dc25....
$ docker logs -f dc25
/\ |‾‾| /‾‾/ /‾/
/\ / \ | |_/ / / /
/ \/ \ | | / ‾‾\
/ \ | |‾\ \ | (_) |
/ __________ \ |__| \__\ \___/ .io
If it matters, here's my script.js:
$ cat ~/k6/script.js
import http from "k6/http";
// Maximum 1 request per second
export let options = {
rps: 1,
duration: 0
}
export default function() {
http.get("http://SERVER-IP-ADDRESS-OF-LOCALHOST");
};
Side note: What's the new correct way of specifying an infinite duration, since duration: 0 is deprecated?
As per the docker documentation
To do input/output with a detached container use network connections or shared volumes. These are required because the container is no longer listening to the command line where docker run was run.
This means that you should probably mount the current directory inside of the docker and run the script from there
docker run -v "`readlink -f .`:/opt" -d loadimpact/k6 run /opt/script.js
-i can be dropped as -d negates it.
Side note: for infinite duration in the future only the manual-executor/manually-controlled (name is still discussed) executor/scheduler will have infinite duration. The executor in question is what will be controlled with the current and future REST API.
For all other executors there will be no infinite duration (at least for now), but for practical implication -d 2000h will probably suffice.
If you provide us with your use case it will be put into consideration for future(and current) plans and changes to the code.
Thanks for the prompt response. Your hints got me there.
I am actually using ansible so here's the working docker_container code in case it helps someone else.
- name: Run k6 Endlessly
docker_container:
name: loadgenerator
image: loadimpact/k6
command: "run /home/ec2-user/script.js"
volumes:
- /home/ec2-user/k6:/home/ec2-user
Most helpful comment
Thanks for the prompt response. Your hints got me there.
I am actually using ansible so here's the working
docker_containercode in case it helps someone else.