go - Docker Golang SDK - How to redirect container stdout to a file -
using docker golang sdk following method can used create container , bind it's output stdout
.
resp, err := cli.containercreate(ctx, &container.config{ image: "alpine", cmd: []string{"echo", "hello world"}, attachstdout: true, }, nil, nil, "")
how can redirect output file using sdk ? i'm using official sdk of docker - github.com/docker/docker/client
you can use below
out, err := cli.containerlogs(ctx, resp.id, types.containerlogsoptions{showstdout: true}) if err != nil { panic(err) } f, err := os.create("/tmp/clogs") io.copy(f, out)
but make sure to after have started container, create create container , not start it
Comments
Post a Comment