Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running k6 docker in detached mode #1035

Closed
ghost opened this issue May 31, 2019 · 2 comments
Closed

Running k6 docker in detached mode #1035

ghost opened this issue May 31, 2019 · 2 comments
Labels

Comments

@ghost
Copy link

ghost commented May 31, 2019

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?

@mstoykov
Copy link
Contributor

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.

@ghost
Copy link
Author

ghost commented May 31, 2019

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

@ghost ghost closed this as completed May 31, 2019
ankur22 added a commit that referenced this issue Oct 5, 2023
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant