// RunDockerCommandAttach attaches to a running Docker container and executes a cmd.
// It should be used to spawn a new pfcpiface process inside and redirect its stdout/stderr to `docker logs`.
// This is equivalent to `docker attach` CLI command.
RunDockerCommandAttach attaches to a running Docker container and executes a cmd.
It should be used to spawn a new pfcpiface process inside and redirect its stdout/stderr to `docker logs`.
This is equivalent to `docker attach` CLI command.
// RunDockerCommandAttach attaches to a running Docker container and executes a cmd . // It should be used to spawn a new pfcpiface process inside and redirect its stdout / stderr to ` docker logs ` . // This is equivalent to ` docker attach ` CLI command .
func RunDockerCommandAttach(container string, cmd string) {
	inout := make(chan []byte)
	ctx := context.Background()
	cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
	if err != nil {
		panic(err)
	}
	defer cli.Close()
	waiter, err := cli.ContainerAttach(ctx, container, types.ContainerAttachOptions{
		Stderr: true,
		Stdout: true,
		Stdin:  true,
		Stream: true,
	})
	go func(w io.WriteCloser) {
		for {
			data, ok := <-inout
			if !ok {
				w.Close()
				return
			}
			w.Write(append(data, '\n'))
		}
	}(waiter.Conn)
	inout <- []byte(cmd)
	waiter.Conn.Close()
	waiter.Close()
}
func RunDockerCommandAttach ( container string , cmd string ) { inout := make ( chan [ ] byte ) ctx := context . Background ( ) cli , err := client . NewClientWithOpts ( client . FromEnv , client . WithAPIVersionNegotiation ( ) ) if err != nil { panic ( err ) } defer cli . Close ( ) waiter , err := cli . ContainerAttach ( ctx , container , types . ContainerAttachOptions { Stderr : true , Stdout : true , Stdin : true , Stream : true , } ) go func ( w io . WriteCloser ) { for { data , ok := <- inout if ! ok { w . Close ( ) return } w . Write ( append ( data , '\n' ) ) } } ( waiter . Conn ) inout <- [ ] byte ( cmd ) waiter . Conn . Close ( ) waiter . Close ( ) }
RunDockerCommandAttach attaches to a running Docker container and executes a cmd.
RunDockerCommandAttach attaches to a running Docker container and executes a cmd .
// Write to docker container