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

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -