Pipes/redirection and stdout/stdin

454 views
Skip to first unread message

Cristina Luis

unread,
Jul 18, 2016, 11:36:44 AM7/18/16
to Nomad
Hi, 

I'm trying to run a couple of chained tasks in a Docker container as a Nomad task and have run into some difficulties.

A command that works outside of Nomad:

 docker run --rm -it ourtask/image:latest sh -c "task arg1 --arg2 val2 | task arga argb"

The only success I've had is by just running the first task as a command. Relevant portion of job spec:

task "loader" {
driver = "docker"

config {
image = "ourtask/image:latest"

command = "task" 
args = [
"arg1",
"--arg2", "val2"
]
}

If I use "sh" as the command with ["task", "arg1", "--arg2", "val2"] as the list of arguments then 'task' gets run but doesn't seem to be receiving the arguments. 

The success example does appear to run properly, based on the log output at alloc/log/loader.stderr.0 but the output of the task, which is emitted to stdout, is nowhere to be found.

So there are two main problems:
1. Passing in a command and args so that the entire line is executed. I realize there are other possibilities, e.g. using artifacts to define more complex config options, but we'll be generating a lot of different jobs using the same tasks and it would be most clear if everything were defined in the job specs. 

2. Where is the output? It won't matter if I can run the whole line if there's no stdout to redirect to the next one.

Thanks,

Cristina 
(Nomad & Docker newbie)

Alex Dadgar

unread,
Jul 18, 2016, 12:32:11 PM7/18/16
to Cristina Luis, Nomad
Hey Cristina,

You can get the arguments to be passed by running:

config {
image = "ourtask/image:latest"

command = "sh" 
args = [
"-c",
"arg1 --arg2 val2"
]
}

As for the logs you can access them via: `nomad fs <alloc-id> alloc/logs/`. That will list the log files and then if you add the file name it will cat them. This workflow will be made easier soon!

Thanks,
Alex

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/nomad/issues
IRC: #nomad-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Nomad" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nomad-tool+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nomad-tool/a97f28d7-140b-4b24-b128-491efd9192e0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Cristina Luis

unread,
Jul 19, 2016, 4:26:52 AM7/19/16
to Nomad
Hi Alex,

Aha, that does work for the whole command with the pipe, thanks! 

There still seems to be a problem with the stdout output when I run just the first task script -- there's nothing in the stdout log (from nomad fs <alloc-id> alloc/logs/). When I add the pipe and the second task script I do get output (from the second task script) in stdout, so the information exists and is getting redirected, but there's no sign of it if I just run the one by itself. Is there some other place it could end up, or something that could cause it not to be saved in the logs? 

Thanks,
Cristina

Alex Dadgar

unread,
Jul 25, 2016, 7:12:16 PM7/25/16
to Cristina Luis, Nomad
Hey Cristina,

If you can run the task locally and it prints to stdout then it should work on Nomad as well. Be aware on your terminal you are seeing both stdout and stderr together. So it may be in the stderr file!

Thanks,
Alex

Reply all
Reply to author
Forward
0 new messages