mirror of https://github.com/docker/docs.git
Generate container JSON client-side and send it in spawn msg
Signed-off-by: Aanand Prasad <aanand.prasad@gmail.com> (github: aanand)
This commit is contained in:
parent
f2f524a11b
commit
16036ec994
|
|
@ -5,7 +5,6 @@ import (
|
|||
"fmt"
|
||||
"github.com/docker/libswarm/beam"
|
||||
"github.com/dotcloud/docker/engine"
|
||||
"github.com/dotcloud/docker/runconfig"
|
||||
"github.com/dotcloud/docker/utils"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
|
|
@ -86,20 +85,10 @@ func (f *forwarder) ls(ctx *beam.Message) error {
|
|||
}
|
||||
|
||||
func (f *forwarder) spawn(ctx *beam.Message) error {
|
||||
if len(ctx.Args) < 1 {
|
||||
return fmt.Errorf("forward: spawn takes at least 1 argument, got %d", len(ctx.Args))
|
||||
if len(ctx.Args) != 1 {
|
||||
return fmt.Errorf("forward: spawn takes exactly 1 argument, got %d", len(ctx.Args))
|
||||
}
|
||||
body, err := json.Marshal(&runconfig.Config{
|
||||
Image: ctx.Args[0],
|
||||
Cmd: ctx.Args[1:],
|
||||
AttachStdin: false,
|
||||
AttachStdout: true,
|
||||
AttachStderr: true,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
resp, err := f.client.call("POST", "/containers/create", string(body))
|
||||
resp, err := f.client.call("POST", "/containers/create", ctx.Args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/docker/libswarm/backends"
|
||||
"github.com/docker/libswarm/beam"
|
||||
"github.com/dotcloud/docker/runconfig"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
|
|
@ -85,7 +87,17 @@ func doCmd(instance *beam.Object, args []string) error {
|
|||
if len(args) < 3 {
|
||||
return fmt.Errorf("usage: run IMAGE COMMAND...")
|
||||
}
|
||||
container, err := instance.Spawn(args[1:]...)
|
||||
containerJson, err := json.Marshal(&runconfig.Config{
|
||||
Image: args[1],
|
||||
Cmd: args[2:],
|
||||
AttachStdin: false,
|
||||
AttachStdout: true,
|
||||
AttachStderr: true,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
container, err := instance.Spawn(string(containerJson))
|
||||
if err != nil {
|
||||
return fmt.Errorf("spawn: %v", err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue