在Docker SDK中从容器中获取输出

我试图运行一个使用Docker SDK的容器,我不能从容器中获得输出。 我使用下面的代码来实际运行容器,但不发送应用程序的stderr和stdout。 你能build议我做错了什么吗?

type dckr struct { cli *client.Client username string password string addr string ctx context.Context } func (d *dckr) Run(containername string, image string, command []string, bind []string, stdout io.Writer, stderr io.Writer) error { log.Printf("[Create] %s -> %s \n", image, containername) res, err := d.cli.ContainerCreate( d.ctx, &container.Config{ User: "root", AttachStdout: true, AttachStderr: true, Image: image, Cmd: command, }, &container.HostConfig{ AutoRemove: true, Binds: bind, }, &network.NetworkingConfig{}, containername, ) if err != nil { log.Println("[Create] Failed. %s", err) return err } defer d.cli.ContainerRemove(d.ctx, res.ID, types.ContainerRemoveOptions{Force: true}) log.Printf("[Create] id: %s \n", res.ID) for wrn := range res.Warnings { log.Printf("[Create] %s \n", wrn) } rsp, err := d.cli.ContainerAttach(d.ctx, containername, types.ContainerAttachOptions{ Stream: false, Stdout: true, Stderr: true, Logs: true, }) if err != nil { log.Printf("[Attach] Fail. %s \n", err) return err } log.Printf("[Attach] %s", res.ID) defer rsp.Close() err = d.cli.ContainerStart(d.ctx, res.ID, types.ContainerStartOptions{}) if err != nil { log.Printf("[Run] Fail. %s \n", err) return err } _, err = stdcopy.StdCopy(stdout, stderr, rsp.Reader) return err }