Guest User

Untitled

a guest
Nov 8th, 2016
586
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 1.00 KB | None | 0 0
  1. func (w *Worker) execcmd(ctx context.Context, cli *client.Client, user string, cmd string) (info types.ContainerExecInspect, err error) {
  2.     ec := types.ExecConfig{}
  3.     ec.Detach = false
  4.     ec.Tty = false
  5.     ec.Cmd = make([]string, 3)
  6.     ec.Cmd[0] = "/bin/bash"
  7.     ec.Cmd[1] = "-c"
  8.     ec.Cmd[2] = cmd
  9.     ec.User = user
  10.     eresp, er := cli.ContainerExecCreate(ctx, w.containerID, ec)
  11.     if er != nil {
  12.         err = errors.Wrap(er, "exec command in container error")
  13.         return
  14.     }
  15.     sc := types.ExecStartCheck{}
  16.     log.Infof("ExecStartCheck %+v", sc)
  17.     sc.Tty = true
  18.     sc.Detach = false
  19.     //log.Infof("exec ID = %s", eresp.ID)
  20.     err = cli.ContainerExecStart(ctx, eresp.ID, sc)
  21.     if err != nil {
  22.         err = errors.Wrap(err, "exec command in container error")
  23.         return
  24.     }
  25.  
  26.     log.Debugf("Executing exec ID = %s", eresp.ID)
  27.  
  28.     info, err = cli.ContainerExecInspect(ctx, eresp.ID)
  29.     log.Infof("ONLY FOR CURRENT DEBUG info.ExitCode = %d", info.ExitCode)
  30.     if err != nil {
  31.         err = errors.Wrap(err, "exec command in container error")
  32.     }
  33.     return
  34. }
Advertisement
Add Comment
Please, Sign In to add comment