#Piping *dagger.Container into functions
1 messages · Page 1 of 1 (latest)
Could do with a section in the docs on this, it's a common question that I and others have asked in the past
So its possible ? I have tried but cant really get it working.
You can 'save' a container in a variable and use that variable elsewhere within the Dagger session yes
#!/usr/bin/env dagger
one=$(container | from alpine)
two=$($one | with-exec "echo,hello")
Something like that should work, I'm not at my desk to check
Yes this works, the approach @frail ember shows works but you can also just do the interpolation directly, saving as a variable is not required
$(container | from alpine) | with-exec "echo,hello" | stdout
So you could do that with dagger shell ? Like:
dagger -c '$(container | from alpine) | with-exec "echo,hello" | stdout'
yes you can. though in that case, since $(container | from alpine) returns a Container type, you can just chain it straight dagger -c 'container | from alpine | with-exec "echo,hello" | stdout'
It gets powerful in situations where you normally can't pipeline straight through and need a subshell to calculate a value you need as an arg to another function, such as
dagger -M -c 'container | from alpine | \
with-exec apk,add,curl | \
with-service-binding web $(container | from nginx | with-exposed-port 80 | as-service) | \
with-exec curl,web | stdout'