|
@@ -1,76 +1,38 @@
|
|
-package api
|
|
|
|
|
|
+package client
|
|
|
|
|
|
import (
|
|
import (
|
|
"bufio"
|
|
"bufio"
|
|
"bytes"
|
|
"bytes"
|
|
"encoding/base64"
|
|
"encoding/base64"
|
|
"encoding/json"
|
|
"encoding/json"
|
|
- "errors"
|
|
|
|
"fmt"
|
|
"fmt"
|
|
- "github.com/dotcloud/docker/archive"
|
|
|
|
- "github.com/dotcloud/docker/auth"
|
|
|
|
- "github.com/dotcloud/docker/dockerversion"
|
|
|
|
- "github.com/dotcloud/docker/engine"
|
|
|
|
- "github.com/dotcloud/docker/nat"
|
|
|
|
- flag "github.com/dotcloud/docker/pkg/mflag"
|
|
|
|
- "github.com/dotcloud/docker/pkg/term"
|
|
|
|
- "github.com/dotcloud/docker/registry"
|
|
|
|
- "github.com/dotcloud/docker/runconfig"
|
|
|
|
- "github.com/dotcloud/docker/utils"
|
|
|
|
"io"
|
|
"io"
|
|
"io/ioutil"
|
|
"io/ioutil"
|
|
- "net"
|
|
|
|
"net/http"
|
|
"net/http"
|
|
- "net/http/httputil"
|
|
|
|
"net/url"
|
|
"net/url"
|
|
"os"
|
|
"os"
|
|
- "os/signal"
|
|
|
|
|
|
+ "os/exec"
|
|
"path"
|
|
"path"
|
|
- "reflect"
|
|
|
|
- "regexp"
|
|
|
|
- "runtime"
|
|
|
|
|
|
+ goruntime "runtime"
|
|
"strconv"
|
|
"strconv"
|
|
"strings"
|
|
"strings"
|
|
"syscall"
|
|
"syscall"
|
|
"text/tabwriter"
|
|
"text/tabwriter"
|
|
"text/template"
|
|
"text/template"
|
|
"time"
|
|
"time"
|
|
-)
|
|
|
|
|
|
|
|
-var funcMap = template.FuncMap{
|
|
|
|
- "json": func(v interface{}) string {
|
|
|
|
- a, _ := json.Marshal(v)
|
|
|
|
- return string(a)
|
|
|
|
- },
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-var (
|
|
|
|
- ErrConnectionRefused = errors.New("Cannot connect to the Docker daemon. Is 'docker -d' running on this host?")
|
|
|
|
|
|
+ "github.com/dotcloud/docker/api"
|
|
|
|
+ "github.com/dotcloud/docker/archive"
|
|
|
|
+ "github.com/dotcloud/docker/dockerversion"
|
|
|
|
+ "github.com/dotcloud/docker/engine"
|
|
|
|
+ "github.com/dotcloud/docker/nat"
|
|
|
|
+ "github.com/dotcloud/docker/pkg/signal"
|
|
|
|
+ "github.com/dotcloud/docker/pkg/term"
|
|
|
|
+ "github.com/dotcloud/docker/registry"
|
|
|
|
+ "github.com/dotcloud/docker/runconfig"
|
|
|
|
+ "github.com/dotcloud/docker/utils"
|
|
)
|
|
)
|
|
|
|
|
|
-func (cli *DockerCli) getMethod(name string) (func(...string) error, bool) {
|
|
|
|
- methodName := "Cmd" + strings.ToUpper(name[:1]) + strings.ToLower(name[1:])
|
|
|
|
- method := reflect.ValueOf(cli).MethodByName(methodName)
|
|
|
|
- if !method.IsValid() {
|
|
|
|
- return nil, false
|
|
|
|
- }
|
|
|
|
- return method.Interface().(func(...string) error), true
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-func ParseCommands(proto, addr string, args ...string) error {
|
|
|
|
- cli := NewDockerCli(os.Stdin, os.Stdout, os.Stderr, proto, addr)
|
|
|
|
-
|
|
|
|
- if len(args) > 0 {
|
|
|
|
- method, exists := cli.getMethod(args[0])
|
|
|
|
- if !exists {
|
|
|
|
- fmt.Println("Error: Command not found:", args[0])
|
|
|
|
- return cli.CmdHelp(args[1:]...)
|
|
|
|
- }
|
|
|
|
- return method(args[1:]...)
|
|
|
|
- }
|
|
|
|
- return cli.CmdHelp(args...)
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
func (cli *DockerCli) CmdHelp(args ...string) error {
|
|
func (cli *DockerCli) CmdHelp(args ...string) error {
|
|
if len(args) > 0 {
|
|
if len(args) > 0 {
|
|
method, exists := cli.getMethod(args[0])
|
|
method, exists := cli.getMethod(args[0])
|
|
@@ -81,7 +43,7 @@ func (cli *DockerCli) CmdHelp(args ...string) error {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- help := fmt.Sprintf("Usage: docker [OPTIONS] COMMAND [arg...]\n -H=[unix://%s]: tcp://host:port to bind/connect to or unix://path/to/socket to use\n\nA self-sufficient runtime for linux containers.\n\nCommands:\n", DEFAULTUNIXSOCKET)
|
|
|
|
|
|
+ help := fmt.Sprintf("Usage: docker [OPTIONS] COMMAND [arg...]\n -H=[unix://%s]: tcp://host:port to bind/connect to or unix://path/to/socket to use\n\nA self-sufficient runtime for linux containers.\n\nCommands:\n", api.DEFAULTUNIXSOCKET)
|
|
for _, command := range [][]string{
|
|
for _, command := range [][]string{
|
|
{"attach", "Attach to a running container"},
|
|
{"attach", "Attach to a running container"},
|
|
{"build", "Build a container from a Dockerfile"},
|
|
{"build", "Build a container from a Dockerfile"},
|
|
@@ -94,7 +56,6 @@ func (cli *DockerCli) CmdHelp(args ...string) error {
|
|
{"images", "List images"},
|
|
{"images", "List images"},
|
|
{"import", "Create a new filesystem image from the contents of a tarball"},
|
|
{"import", "Create a new filesystem image from the contents of a tarball"},
|
|
{"info", "Display system-wide information"},
|
|
{"info", "Display system-wide information"},
|
|
- {"insert", "Insert a file in an image"},
|
|
|
|
{"inspect", "Return low-level information on a container"},
|
|
{"inspect", "Return low-level information on a container"},
|
|
{"kill", "Kill a running container"},
|
|
{"kill", "Kill a running container"},
|
|
{"load", "Load an image from a tar archive"},
|
|
{"load", "Load an image from a tar archive"},
|
|
@@ -123,7 +84,9 @@ func (cli *DockerCli) CmdHelp(args ...string) error {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// FIXME: 'insert' is deprecated.
|
|
func (cli *DockerCli) CmdInsert(args ...string) error {
|
|
func (cli *DockerCli) CmdInsert(args ...string) error {
|
|
|
|
+ fmt.Fprintf(os.Stderr, "Warning: '%s' is deprecated and will be removed in a future version. Please use 'docker build' and 'ADD' instead.\n")
|
|
cmd := cli.Subcmd("insert", "IMAGE URL PATH", "Insert a file from URL in the IMAGE at PATH")
|
|
cmd := cli.Subcmd("insert", "IMAGE URL PATH", "Insert a file from URL in the IMAGE at PATH")
|
|
if err := cmd.Parse(args); err != nil {
|
|
if err := cmd.Parse(args); err != nil {
|
|
return nil
|
|
return nil
|
|
@@ -160,6 +123,8 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
|
|
err error
|
|
err error
|
|
)
|
|
)
|
|
|
|
|
|
|
|
+ _, err = exec.LookPath("git")
|
|
|
|
+ hasGit := err == nil
|
|
if cmd.Arg(0) == "-" {
|
|
if cmd.Arg(0) == "-" {
|
|
// As a special case, 'docker build -' will build from an empty context with the
|
|
// As a special case, 'docker build -' will build from an empty context with the
|
|
// contents of stdin as a Dockerfile
|
|
// contents of stdin as a Dockerfile
|
|
@@ -168,17 +133,34 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
context, err = archive.Generate("Dockerfile", string(dockerfile))
|
|
context, err = archive.Generate("Dockerfile", string(dockerfile))
|
|
- } else if utils.IsURL(cmd.Arg(0)) || utils.IsGIT(cmd.Arg(0)) {
|
|
|
|
|
|
+ } else if utils.IsURL(cmd.Arg(0)) && (!utils.IsGIT(cmd.Arg(0)) || !hasGit) {
|
|
isRemote = true
|
|
isRemote = true
|
|
} else {
|
|
} else {
|
|
- if _, err := os.Stat(cmd.Arg(0)); err != nil {
|
|
|
|
|
|
+ root := cmd.Arg(0)
|
|
|
|
+ if utils.IsGIT(root) {
|
|
|
|
+ remoteURL := cmd.Arg(0)
|
|
|
|
+ if !strings.HasPrefix(remoteURL, "git://") && !strings.HasPrefix(remoteURL, "git@") && !utils.IsURL(remoteURL) {
|
|
|
|
+ remoteURL = "https://" + remoteURL
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ root, err = ioutil.TempDir("", "docker-build-git")
|
|
|
|
+ if err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+ defer os.RemoveAll(root)
|
|
|
|
+
|
|
|
|
+ if output, err := exec.Command("git", "clone", "--recursive", remoteURL, root).CombinedOutput(); err != nil {
|
|
|
|
+ return fmt.Errorf("Error trying to use git: %s (%s)", err, output)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if _, err := os.Stat(root); err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
- filename := path.Join(cmd.Arg(0), "Dockerfile")
|
|
|
|
|
|
+ filename := path.Join(root, "Dockerfile")
|
|
if _, err = os.Stat(filename); os.IsNotExist(err) {
|
|
if _, err = os.Stat(filename); os.IsNotExist(err) {
|
|
return fmt.Errorf("no Dockerfile found in %s", cmd.Arg(0))
|
|
return fmt.Errorf("no Dockerfile found in %s", cmd.Arg(0))
|
|
}
|
|
}
|
|
- context, err = archive.Tar(cmd.Arg(0), archive.Uncompressed)
|
|
|
|
|
|
+ context, err = archive.Tar(root, archive.Uncompressed)
|
|
}
|
|
}
|
|
var body io.Reader
|
|
var body io.Reader
|
|
// Setup an upload progress bar
|
|
// Setup an upload progress bar
|
|
@@ -189,6 +171,15 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
|
|
}
|
|
}
|
|
// Upload the build context
|
|
// Upload the build context
|
|
v := &url.Values{}
|
|
v := &url.Values{}
|
|
|
|
+
|
|
|
|
+ //Check if the given image name can be resolved
|
|
|
|
+ if *tag != "" {
|
|
|
|
+ repository, _ := utils.ParseRepositoryTag(*tag)
|
|
|
|
+ if _, _, err := registry.ResolveRepositoryName(repository); err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
v.Set("t", *tag)
|
|
v.Set("t", *tag)
|
|
|
|
|
|
if *suppressOutput {
|
|
if *suppressOutput {
|
|
@@ -229,7 +220,7 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
|
|
|
|
|
|
// 'docker login': login / register a user to registry service.
|
|
// 'docker login': login / register a user to registry service.
|
|
func (cli *DockerCli) CmdLogin(args ...string) error {
|
|
func (cli *DockerCli) CmdLogin(args ...string) error {
|
|
- cmd := cli.Subcmd("login", "[OPTIONS] [SERVER]", "Register or Login to a docker registry server, if no server is specified \""+auth.IndexServerAddress()+"\" is the default.")
|
|
|
|
|
|
+ cmd := cli.Subcmd("login", "[OPTIONS] [SERVER]", "Register or Login to a docker registry server, if no server is specified \""+registry.IndexServerAddress()+"\" is the default.")
|
|
|
|
|
|
var username, password, email string
|
|
var username, password, email string
|
|
|
|
|
|
@@ -240,7 +231,7 @@ func (cli *DockerCli) CmdLogin(args ...string) error {
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
- serverAddress := auth.IndexServerAddress()
|
|
|
|
|
|
+ serverAddress := registry.IndexServerAddress()
|
|
if len(cmd.Args()) > 0 {
|
|
if len(cmd.Args()) > 0 {
|
|
serverAddress = cmd.Arg(0)
|
|
serverAddress = cmd.Arg(0)
|
|
}
|
|
}
|
|
@@ -266,7 +257,7 @@ func (cli *DockerCli) CmdLogin(args ...string) error {
|
|
cli.LoadConfigFile()
|
|
cli.LoadConfigFile()
|
|
authconfig, ok := cli.configFile.Configs[serverAddress]
|
|
authconfig, ok := cli.configFile.Configs[serverAddress]
|
|
if !ok {
|
|
if !ok {
|
|
- authconfig = auth.AuthConfig{}
|
|
|
|
|
|
+ authconfig = registry.AuthConfig{}
|
|
}
|
|
}
|
|
|
|
|
|
if username == "" {
|
|
if username == "" {
|
|
@@ -311,7 +302,7 @@ func (cli *DockerCli) CmdLogin(args ...string) error {
|
|
stream, statusCode, err := cli.call("POST", "/auth", cli.configFile.Configs[serverAddress], false)
|
|
stream, statusCode, err := cli.call("POST", "/auth", cli.configFile.Configs[serverAddress], false)
|
|
if statusCode == 401 {
|
|
if statusCode == 401 {
|
|
delete(cli.configFile.Configs, serverAddress)
|
|
delete(cli.configFile.Configs, serverAddress)
|
|
- auth.SaveConfig(cli.configFile)
|
|
|
|
|
|
+ registry.SaveConfig(cli.configFile)
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -320,10 +311,10 @@ func (cli *DockerCli) CmdLogin(args ...string) error {
|
|
var out2 engine.Env
|
|
var out2 engine.Env
|
|
err = out2.Decode(stream)
|
|
err = out2.Decode(stream)
|
|
if err != nil {
|
|
if err != nil {
|
|
- cli.configFile, _ = auth.LoadConfig(os.Getenv("HOME"))
|
|
|
|
|
|
+ cli.configFile, _ = registry.LoadConfig(os.Getenv("HOME"))
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
- auth.SaveConfig(cli.configFile)
|
|
|
|
|
|
+ registry.SaveConfig(cli.configFile)
|
|
if out2.Get("Status") != "" {
|
|
if out2.Get("Status") != "" {
|
|
fmt.Fprintf(cli.out, "%s\n", out2.Get("Status"))
|
|
fmt.Fprintf(cli.out, "%s\n", out2.Get("Status"))
|
|
}
|
|
}
|
|
@@ -367,7 +358,8 @@ func (cli *DockerCli) CmdVersion(args ...string) error {
|
|
if dockerversion.VERSION != "" {
|
|
if dockerversion.VERSION != "" {
|
|
fmt.Fprintf(cli.out, "Client version: %s\n", dockerversion.VERSION)
|
|
fmt.Fprintf(cli.out, "Client version: %s\n", dockerversion.VERSION)
|
|
}
|
|
}
|
|
- fmt.Fprintf(cli.out, "Go version (client): %s\n", runtime.Version())
|
|
|
|
|
|
+ fmt.Fprintf(cli.out, "Client API version: %s\n", api.APIVERSION)
|
|
|
|
+ fmt.Fprintf(cli.out, "Go version (client): %s\n", goruntime.Version())
|
|
if dockerversion.GITCOMMIT != "" {
|
|
if dockerversion.GITCOMMIT != "" {
|
|
fmt.Fprintf(cli.out, "Git commit (client): %s\n", dockerversion.GITCOMMIT)
|
|
fmt.Fprintf(cli.out, "Git commit (client): %s\n", dockerversion.GITCOMMIT)
|
|
}
|
|
}
|
|
@@ -389,6 +381,9 @@ func (cli *DockerCli) CmdVersion(args ...string) error {
|
|
}
|
|
}
|
|
out.Close()
|
|
out.Close()
|
|
fmt.Fprintf(cli.out, "Server version: %s\n", remoteVersion.Get("Version"))
|
|
fmt.Fprintf(cli.out, "Server version: %s\n", remoteVersion.Get("Version"))
|
|
|
|
+ if apiVersion := remoteVersion.Get("ApiVersion"); apiVersion != "" {
|
|
|
|
+ fmt.Fprintf(cli.out, "Server API version: %s\n", apiVersion)
|
|
|
|
+ }
|
|
fmt.Fprintf(cli.out, "Git commit (server): %s\n", remoteVersion.Get("GitCommit"))
|
|
fmt.Fprintf(cli.out, "Git commit (server): %s\n", remoteVersion.Get("GitCommit"))
|
|
fmt.Fprintf(cli.out, "Go version (server): %s\n", remoteVersion.Get("GoVersion"))
|
|
fmt.Fprintf(cli.out, "Go version (server): %s\n", remoteVersion.Get("GoVersion"))
|
|
release := utils.GetReleaseVersion()
|
|
release := utils.GetReleaseVersion()
|
|
@@ -432,7 +427,7 @@ func (cli *DockerCli) CmdInfo(args ...string) error {
|
|
|
|
|
|
fmt.Fprintf(cli.out, "Containers: %d\n", remoteInfo.GetInt("Containers"))
|
|
fmt.Fprintf(cli.out, "Containers: %d\n", remoteInfo.GetInt("Containers"))
|
|
fmt.Fprintf(cli.out, "Images: %d\n", remoteInfo.GetInt("Images"))
|
|
fmt.Fprintf(cli.out, "Images: %d\n", remoteInfo.GetInt("Images"))
|
|
- fmt.Fprintf(cli.out, "Driver: %s\n", remoteInfo.Get("Driver"))
|
|
|
|
|
|
+ fmt.Fprintf(cli.out, "Storage Driver: %s\n", remoteInfo.Get("Driver"))
|
|
var driverStatus [][2]string
|
|
var driverStatus [][2]string
|
|
if err := remoteInfo.GetJson("DriverStatus", &driverStatus); err != nil {
|
|
if err := remoteInfo.GetJson("DriverStatus", &driverStatus); err != nil {
|
|
return err
|
|
return err
|
|
@@ -440,14 +435,15 @@ func (cli *DockerCli) CmdInfo(args ...string) error {
|
|
for _, pair := range driverStatus {
|
|
for _, pair := range driverStatus {
|
|
fmt.Fprintf(cli.out, " %s: %s\n", pair[0], pair[1])
|
|
fmt.Fprintf(cli.out, " %s: %s\n", pair[0], pair[1])
|
|
}
|
|
}
|
|
|
|
+ fmt.Fprintf(cli.out, "Execution Driver: %s\n", remoteInfo.Get("ExecutionDriver"))
|
|
|
|
+ fmt.Fprintf(cli.out, "Kernel Version: %s\n", remoteInfo.Get("KernelVersion"))
|
|
|
|
+
|
|
if remoteInfo.GetBool("Debug") || os.Getenv("DEBUG") != "" {
|
|
if remoteInfo.GetBool("Debug") || os.Getenv("DEBUG") != "" {
|
|
fmt.Fprintf(cli.out, "Debug mode (server): %v\n", remoteInfo.GetBool("Debug"))
|
|
fmt.Fprintf(cli.out, "Debug mode (server): %v\n", remoteInfo.GetBool("Debug"))
|
|
fmt.Fprintf(cli.out, "Debug mode (client): %v\n", os.Getenv("DEBUG") != "")
|
|
fmt.Fprintf(cli.out, "Debug mode (client): %v\n", os.Getenv("DEBUG") != "")
|
|
fmt.Fprintf(cli.out, "Fds: %d\n", remoteInfo.GetInt("NFd"))
|
|
fmt.Fprintf(cli.out, "Fds: %d\n", remoteInfo.GetInt("NFd"))
|
|
fmt.Fprintf(cli.out, "Goroutines: %d\n", remoteInfo.GetInt("NGoroutines"))
|
|
fmt.Fprintf(cli.out, "Goroutines: %d\n", remoteInfo.GetInt("NGoroutines"))
|
|
- fmt.Fprintf(cli.out, "Execution Driver: %s\n", remoteInfo.Get("ExecutionDriver"))
|
|
|
|
fmt.Fprintf(cli.out, "EventsListeners: %d\n", remoteInfo.GetInt("NEventsListener"))
|
|
fmt.Fprintf(cli.out, "EventsListeners: %d\n", remoteInfo.GetInt("NEventsListener"))
|
|
- fmt.Fprintf(cli.out, "Kernel Version: %s\n", remoteInfo.Get("KernelVersion"))
|
|
|
|
|
|
|
|
if initSha1 := remoteInfo.Get("InitSha1"); initSha1 != "" {
|
|
if initSha1 := remoteInfo.Get("InitSha1"); initSha1 != "" {
|
|
fmt.Fprintf(cli.out, "Init SHA1: %s\n", initSha1)
|
|
fmt.Fprintf(cli.out, "Init SHA1: %s\n", initSha1)
|
|
@@ -533,13 +529,23 @@ func (cli *DockerCli) CmdRestart(args ...string) error {
|
|
|
|
|
|
func (cli *DockerCli) forwardAllSignals(cid string) chan os.Signal {
|
|
func (cli *DockerCli) forwardAllSignals(cid string) chan os.Signal {
|
|
sigc := make(chan os.Signal, 1)
|
|
sigc := make(chan os.Signal, 1)
|
|
- utils.CatchAll(sigc)
|
|
|
|
|
|
+ signal.CatchAll(sigc)
|
|
go func() {
|
|
go func() {
|
|
for s := range sigc {
|
|
for s := range sigc {
|
|
if s == syscall.SIGCHLD {
|
|
if s == syscall.SIGCHLD {
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
- if _, _, err := readBody(cli.call("POST", fmt.Sprintf("/containers/%s/kill?signal=%d", cid, s), nil, false)); err != nil {
|
|
|
|
|
|
+ var sig string
|
|
|
|
+ for sigStr, sigN := range signal.SignalMap {
|
|
|
|
+ if sigN == s {
|
|
|
|
+ sig = sigStr
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if sig == "" {
|
|
|
|
+ utils.Errorf("Unsupported signal: %d. Discarding.", s)
|
|
|
|
+ }
|
|
|
|
+ if _, _, err := readBody(cli.call("POST", fmt.Sprintf("/containers/%s/kill?signal=%s", cid, sig), nil, false)); err != nil {
|
|
utils.Debugf("Error sending signal: %s", err)
|
|
utils.Debugf("Error sending signal: %s", err)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -548,9 +554,11 @@ func (cli *DockerCli) forwardAllSignals(cid string) chan os.Signal {
|
|
}
|
|
}
|
|
|
|
|
|
func (cli *DockerCli) CmdStart(args ...string) error {
|
|
func (cli *DockerCli) CmdStart(args ...string) error {
|
|
- cmd := cli.Subcmd("start", "CONTAINER [CONTAINER...]", "Restart a stopped container")
|
|
|
|
- attach := cmd.Bool([]string{"a", "-attach"}, false, "Attach container's stdout/stderr and forward all signals to the process")
|
|
|
|
- openStdin := cmd.Bool([]string{"i", "-interactive"}, false, "Attach container's stdin")
|
|
|
|
|
|
+ var (
|
|
|
|
+ cmd = cli.Subcmd("start", "CONTAINER [CONTAINER...]", "Restart a stopped container")
|
|
|
|
+ attach = cmd.Bool([]string{"a", "-attach"}, false, "Attach container's stdout/stderr and forward all signals to the process")
|
|
|
|
+ openStdin = cmd.Bool([]string{"i", "-interactive"}, false, "Attach container's stdin")
|
|
|
|
+ )
|
|
if err := cmd.Parse(args); err != nil {
|
|
if err := cmd.Parse(args); err != nil {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
@@ -559,8 +567,10 @@ func (cli *DockerCli) CmdStart(args ...string) error {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
- var cErr chan error
|
|
|
|
- var tty bool
|
|
|
|
|
|
+ var (
|
|
|
|
+ cErr chan error
|
|
|
|
+ tty bool
|
|
|
|
+ )
|
|
if *attach || *openStdin {
|
|
if *attach || *openStdin {
|
|
if cmd.NArg() > 1 {
|
|
if cmd.NArg() > 1 {
|
|
return fmt.Errorf("You cannot start and attach multiple containers at once.")
|
|
return fmt.Errorf("You cannot start and attach multiple containers at once.")
|
|
@@ -571,7 +581,7 @@ func (cli *DockerCli) CmdStart(args ...string) error {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
|
|
|
|
- container := &Container{}
|
|
|
|
|
|
+ container := &api.Container{}
|
|
err = json.Unmarshal(body, container)
|
|
err = json.Unmarshal(body, container)
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
@@ -581,7 +591,7 @@ func (cli *DockerCli) CmdStart(args ...string) error {
|
|
|
|
|
|
if !container.Config.Tty {
|
|
if !container.Config.Tty {
|
|
sigc := cli.forwardAllSignals(cmd.Arg(0))
|
|
sigc := cli.forwardAllSignals(cmd.Arg(0))
|
|
- defer utils.StopCatch(sigc)
|
|
|
|
|
|
+ defer signal.StopCatch(sigc)
|
|
}
|
|
}
|
|
|
|
|
|
var in io.ReadCloser
|
|
var in io.ReadCloser
|
|
@@ -606,8 +616,8 @@ func (cli *DockerCli) CmdStart(args ...string) error {
|
|
if err != nil {
|
|
if err != nil {
|
|
if !*attach || !*openStdin {
|
|
if !*attach || !*openStdin {
|
|
fmt.Fprintf(cli.err, "%s\n", err)
|
|
fmt.Fprintf(cli.err, "%s\n", err)
|
|
- encounteredError = fmt.Errorf("Error: failed to start one or more containers")
|
|
|
|
}
|
|
}
|
|
|
|
+ encounteredError = fmt.Errorf("Error: failed to start one or more containers")
|
|
} else {
|
|
} else {
|
|
if !*attach || !*openStdin {
|
|
if !*attach || !*openStdin {
|
|
fmt.Fprintf(cli.out, "%s\n", name)
|
|
fmt.Fprintf(cli.out, "%s\n", name)
|
|
@@ -758,9 +768,13 @@ func (cli *DockerCli) CmdPort(args ...string) error {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
- port := cmd.Arg(1)
|
|
|
|
- proto := "tcp"
|
|
|
|
- parts := strings.SplitN(port, "/", 2)
|
|
|
|
|
|
+ var (
|
|
|
|
+ port = cmd.Arg(1)
|
|
|
|
+ proto = "tcp"
|
|
|
|
+ parts = strings.SplitN(port, "/", 2)
|
|
|
|
+ container api.Container
|
|
|
|
+ )
|
|
|
|
+
|
|
if len(parts) == 2 && len(parts[1]) != 0 {
|
|
if len(parts) == 2 && len(parts[1]) != 0 {
|
|
port = parts[0]
|
|
port = parts[0]
|
|
proto = parts[1]
|
|
proto = parts[1]
|
|
@@ -769,13 +783,13 @@ func (cli *DockerCli) CmdPort(args ...string) error {
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
- var out Container
|
|
|
|
- err = json.Unmarshal(body, &out)
|
|
|
|
|
|
+
|
|
|
|
+ err = json.Unmarshal(body, &container)
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
|
|
|
|
- if frontends, exists := out.NetworkSettings.Ports[nat.Port(port+"/"+proto)]; exists && frontends != nil {
|
|
|
|
|
|
+ if frontends, exists := container.NetworkSettings.Ports[nat.Port(port+"/"+proto)]; exists && frontends != nil {
|
|
for _, frontend := range frontends {
|
|
for _, frontend := range frontends {
|
|
fmt.Fprintf(cli.out, "%s:%s\n", frontend.HostIp, frontend.HostPort)
|
|
fmt.Fprintf(cli.out, "%s:%s\n", frontend.HostIp, frontend.HostPort)
|
|
}
|
|
}
|
|
@@ -788,8 +802,9 @@ func (cli *DockerCli) CmdPort(args ...string) error {
|
|
// 'docker rmi IMAGE' removes all images with the name IMAGE
|
|
// 'docker rmi IMAGE' removes all images with the name IMAGE
|
|
func (cli *DockerCli) CmdRmi(args ...string) error {
|
|
func (cli *DockerCli) CmdRmi(args ...string) error {
|
|
var (
|
|
var (
|
|
- cmd = cli.Subcmd("rmi", "IMAGE [IMAGE...]", "Remove one or more images")
|
|
|
|
- force = cmd.Bool([]string{"f", "-force"}, false, "Force")
|
|
|
|
|
|
+ cmd = cli.Subcmd("rmi", "IMAGE [IMAGE...]", "Remove one or more images")
|
|
|
|
+ force = cmd.Bool([]string{"f", "-force"}, false, "Force")
|
|
|
|
+ noprune = cmd.Bool([]string{"-no-prune"}, false, "Do not delete untagged parents")
|
|
)
|
|
)
|
|
if err := cmd.Parse(args); err != nil {
|
|
if err := cmd.Parse(args); err != nil {
|
|
return nil
|
|
return nil
|
|
@@ -803,6 +818,9 @@ func (cli *DockerCli) CmdRmi(args ...string) error {
|
|
if *force {
|
|
if *force {
|
|
v.Set("force", "1")
|
|
v.Set("force", "1")
|
|
}
|
|
}
|
|
|
|
+ if *noprune {
|
|
|
|
+ v.Set("noprune", "1")
|
|
|
|
+ }
|
|
|
|
|
|
var encounteredError error
|
|
var encounteredError error
|
|
for _, name := range cmd.Args() {
|
|
for _, name := range cmd.Args() {
|
|
@@ -969,6 +987,14 @@ func (cli *DockerCli) CmdImport(args ...string) error {
|
|
repository, tag = utils.ParseRepositoryTag(cmd.Arg(1))
|
|
repository, tag = utils.ParseRepositoryTag(cmd.Arg(1))
|
|
}
|
|
}
|
|
v := url.Values{}
|
|
v := url.Values{}
|
|
|
|
+
|
|
|
|
+ if repository != "" {
|
|
|
|
+ //Check if the given image name can be resolved
|
|
|
|
+ if _, _, err := registry.ResolveRepositoryName(repository); err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
v.Set("repo", repository)
|
|
v.Set("repo", repository)
|
|
v.Set("tag", tag)
|
|
v.Set("tag", tag)
|
|
v.Set("fromSrc", src)
|
|
v.Set("fromSrc", src)
|
|
@@ -983,7 +1009,7 @@ func (cli *DockerCli) CmdImport(args ...string) error {
|
|
}
|
|
}
|
|
|
|
|
|
func (cli *DockerCli) CmdPush(args ...string) error {
|
|
func (cli *DockerCli) CmdPush(args ...string) error {
|
|
- cmd := cli.Subcmd("push", "NAME", "Push an image or a repository to the registry")
|
|
|
|
|
|
+ cmd := cli.Subcmd("push", "NAME[:TAG]", "Push an image or a repository to the registry")
|
|
if err := cmd.Parse(args); err != nil {
|
|
if err := cmd.Parse(args); err != nil {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
@@ -996,8 +1022,10 @@ func (cli *DockerCli) CmdPush(args ...string) error {
|
|
|
|
|
|
cli.LoadConfigFile()
|
|
cli.LoadConfigFile()
|
|
|
|
|
|
|
|
+ remote, tag := utils.ParseRepositoryTag(name)
|
|
|
|
+
|
|
// Resolve the Repository name from fqn to hostname + name
|
|
// Resolve the Repository name from fqn to hostname + name
|
|
- hostname, _, err := registry.ResolveRepositoryName(name)
|
|
|
|
|
|
+ hostname, _, err := registry.ResolveRepositoryName(remote)
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
@@ -1008,7 +1036,7 @@ func (cli *DockerCli) CmdPush(args ...string) error {
|
|
// Custom repositories can have different rules, and we must also
|
|
// Custom repositories can have different rules, and we must also
|
|
// allow pushing by image ID.
|
|
// allow pushing by image ID.
|
|
if len(strings.SplitN(name, "/", 2)) == 1 {
|
|
if len(strings.SplitN(name, "/", 2)) == 1 {
|
|
- username := cli.configFile.Configs[auth.IndexServerAddress()].Username
|
|
|
|
|
|
+ username := cli.configFile.Configs[registry.IndexServerAddress()].Username
|
|
if username == "" {
|
|
if username == "" {
|
|
username = "<user>"
|
|
username = "<user>"
|
|
}
|
|
}
|
|
@@ -1016,7 +1044,8 @@ func (cli *DockerCli) CmdPush(args ...string) error {
|
|
}
|
|
}
|
|
|
|
|
|
v := url.Values{}
|
|
v := url.Values{}
|
|
- push := func(authConfig auth.AuthConfig) error {
|
|
|
|
|
|
+ v.Set("tag", tag)
|
|
|
|
+ push := func(authConfig registry.AuthConfig) error {
|
|
buf, err := json.Marshal(authConfig)
|
|
buf, err := json.Marshal(authConfig)
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
@@ -1025,7 +1054,7 @@ func (cli *DockerCli) CmdPush(args ...string) error {
|
|
base64.URLEncoding.EncodeToString(buf),
|
|
base64.URLEncoding.EncodeToString(buf),
|
|
}
|
|
}
|
|
|
|
|
|
- return cli.stream("POST", "/images/"+name+"/push?"+v.Encode(), nil, cli.out, map[string][]string{
|
|
|
|
|
|
+ return cli.stream("POST", "/images/"+remote+"/push?"+v.Encode(), nil, cli.out, map[string][]string{
|
|
"X-Registry-Auth": registryAuthHeader,
|
|
"X-Registry-Auth": registryAuthHeader,
|
|
})
|
|
})
|
|
}
|
|
}
|
|
@@ -1045,8 +1074,8 @@ func (cli *DockerCli) CmdPush(args ...string) error {
|
|
}
|
|
}
|
|
|
|
|
|
func (cli *DockerCli) CmdPull(args ...string) error {
|
|
func (cli *DockerCli) CmdPull(args ...string) error {
|
|
- cmd := cli.Subcmd("pull", "NAME", "Pull an image or a repository from the registry")
|
|
|
|
- tag := cmd.String([]string{"t", "-tag"}, "", "Download tagged image in repository")
|
|
|
|
|
|
+ cmd := cli.Subcmd("pull", "NAME[:TAG]", "Pull an image or a repository from the registry")
|
|
|
|
+ tag := cmd.String([]string{"#t", "#-tag"}, "", "Download tagged image in repository")
|
|
if err := cmd.Parse(args); err != nil {
|
|
if err := cmd.Parse(args); err != nil {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
@@ -1075,7 +1104,7 @@ func (cli *DockerCli) CmdPull(args ...string) error {
|
|
v.Set("fromImage", remote)
|
|
v.Set("fromImage", remote)
|
|
v.Set("tag", *tag)
|
|
v.Set("tag", *tag)
|
|
|
|
|
|
- pull := func(authConfig auth.AuthConfig) error {
|
|
|
|
|
|
+ pull := func(authConfig registry.AuthConfig) error {
|
|
buf, err := json.Marshal(authConfig)
|
|
buf, err := json.Marshal(authConfig)
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
@@ -1107,10 +1136,11 @@ func (cli *DockerCli) CmdPull(args ...string) error {
|
|
func (cli *DockerCli) CmdImages(args ...string) error {
|
|
func (cli *DockerCli) CmdImages(args ...string) error {
|
|
cmd := cli.Subcmd("images", "[OPTIONS] [NAME]", "List images")
|
|
cmd := cli.Subcmd("images", "[OPTIONS] [NAME]", "List images")
|
|
quiet := cmd.Bool([]string{"q", "-quiet"}, false, "Only show numeric IDs")
|
|
quiet := cmd.Bool([]string{"q", "-quiet"}, false, "Only show numeric IDs")
|
|
- all := cmd.Bool([]string{"a", "-all"}, false, "Show all images (by default filter out the intermediate images used to build)")
|
|
|
|
|
|
+ all := cmd.Bool([]string{"a", "-all"}, false, "Show all images (by default filter out the intermediate image layers)")
|
|
noTrunc := cmd.Bool([]string{"#notrunc", "-no-trunc"}, false, "Don't truncate output")
|
|
noTrunc := cmd.Bool([]string{"#notrunc", "-no-trunc"}, false, "Don't truncate output")
|
|
- flViz := cmd.Bool([]string{"v", "#viz", "-viz"}, false, "Output graph in graphviz format")
|
|
|
|
- flTree := cmd.Bool([]string{"t", "#tree", "-tree"}, false, "Output graph in tree format")
|
|
|
|
|
|
+ // FIXME: --viz and --tree are deprecated. Remove them in a future version.
|
|
|
|
+ flViz := cmd.Bool([]string{"#v", "#viz", "#-viz"}, false, "Output graph in graphviz format")
|
|
|
|
+ flTree := cmd.Bool([]string{"#t", "#tree", "#-tree"}, false, "Output graph in tree format")
|
|
|
|
|
|
if err := cmd.Parse(args); err != nil {
|
|
if err := cmd.Parse(args); err != nil {
|
|
return nil
|
|
return nil
|
|
@@ -1122,6 +1152,7 @@ func (cli *DockerCli) CmdImages(args ...string) error {
|
|
|
|
|
|
filter := cmd.Arg(0)
|
|
filter := cmd.Arg(0)
|
|
|
|
|
|
|
|
+ // FIXME: --viz and --tree are deprecated. Remove them in a future version.
|
|
if *flViz || *flTree {
|
|
if *flViz || *flTree {
|
|
body, _, err := readBody(cli.call("GET", "/images/json?all=1", nil, false))
|
|
body, _, err := readBody(cli.call("GET", "/images/json?all=1", nil, false))
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -1232,6 +1263,7 @@ func (cli *DockerCli) CmdImages(args ...string) error {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// FIXME: --viz and --tree are deprecated. Remove them in a future version.
|
|
func (cli *DockerCli) WalkTree(noTrunc bool, images *engine.Table, byParent map[string]*engine.Table, prefix string, printNode func(cli *DockerCli, noTrunc bool, image *engine.Env, prefix string)) {
|
|
func (cli *DockerCli) WalkTree(noTrunc bool, images *engine.Table, byParent map[string]*engine.Table, prefix string, printNode func(cli *DockerCli, noTrunc bool, image *engine.Env, prefix string)) {
|
|
length := images.Len()
|
|
length := images.Len()
|
|
if length > 1 {
|
|
if length > 1 {
|
|
@@ -1258,6 +1290,7 @@ func (cli *DockerCli) WalkTree(noTrunc bool, images *engine.Table, byParent map[
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// FIXME: --viz and --tree are deprecated. Remove them in a future version.
|
|
func (cli *DockerCli) printVizNode(noTrunc bool, image *engine.Env, prefix string) {
|
|
func (cli *DockerCli) printVizNode(noTrunc bool, image *engine.Env, prefix string) {
|
|
var (
|
|
var (
|
|
imageID string
|
|
imageID string
|
|
@@ -1281,6 +1314,7 @@ func (cli *DockerCli) printVizNode(noTrunc bool, image *engine.Env, prefix strin
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// FIXME: --viz and --tree are deprecated. Remove them in a future version.
|
|
func (cli *DockerCli) printTreeNode(noTrunc bool, image *engine.Env, prefix string) {
|
|
func (cli *DockerCli) printTreeNode(noTrunc bool, image *engine.Env, prefix string) {
|
|
var imageID string
|
|
var imageID string
|
|
if noTrunc {
|
|
if noTrunc {
|
|
@@ -1304,8 +1338,8 @@ func (cli *DockerCli) CmdPs(args ...string) error {
|
|
all := cmd.Bool([]string{"a", "-all"}, false, "Show all containers. Only running containers are shown by default.")
|
|
all := cmd.Bool([]string{"a", "-all"}, false, "Show all containers. Only running containers are shown by default.")
|
|
noTrunc := cmd.Bool([]string{"#notrunc", "-no-trunc"}, false, "Don't truncate output")
|
|
noTrunc := cmd.Bool([]string{"#notrunc", "-no-trunc"}, false, "Don't truncate output")
|
|
nLatest := cmd.Bool([]string{"l", "-latest"}, false, "Show only the latest created container, include non-running ones.")
|
|
nLatest := cmd.Bool([]string{"l", "-latest"}, false, "Show only the latest created container, include non-running ones.")
|
|
- since := cmd.String([]string{"#sinceId", "-since-id"}, "", "Show only containers created since Id, include non-running ones.")
|
|
|
|
- before := cmd.String([]string{"#beforeId", "-before-id"}, "", "Show only container created before Id, include non-running ones.")
|
|
|
|
|
|
+ since := cmd.String([]string{"#sinceId", "#-since-id", "-since"}, "", "Show only containers created since Id or Name, include non-running ones.")
|
|
|
|
+ before := cmd.String([]string{"#beforeId", "#-before-id", "-before"}, "", "Show only container created before Id or Name, include non-running ones.")
|
|
last := cmd.Int([]string{"n"}, -1, "Show n last created containers, include non-running ones.")
|
|
last := cmd.Int([]string{"n"}, -1, "Show n last created containers, include non-running ones.")
|
|
|
|
|
|
if err := cmd.Parse(args); err != nil {
|
|
if err := cmd.Parse(args); err != nil {
|
|
@@ -1374,7 +1408,7 @@ func (cli *DockerCli) CmdPs(args ...string) error {
|
|
outCommand = utils.Trunc(outCommand, 20)
|
|
outCommand = utils.Trunc(outCommand, 20)
|
|
}
|
|
}
|
|
ports.ReadListFrom([]byte(out.Get("Ports")))
|
|
ports.ReadListFrom([]byte(out.Get("Ports")))
|
|
- fmt.Fprintf(w, "%s\t%s\t%s\t%s ago\t%s\t%s\t%s\t", outID, out.Get("Image"), outCommand, utils.HumanDuration(time.Now().UTC().Sub(time.Unix(out.GetInt64("Created"), 0))), out.Get("Status"), displayablePorts(ports), strings.Join(outNames, ","))
|
|
|
|
|
|
+ fmt.Fprintf(w, "%s\t%s\t%s\t%s ago\t%s\t%s\t%s\t", outID, out.Get("Image"), outCommand, utils.HumanDuration(time.Now().UTC().Sub(time.Unix(out.GetInt64("Created"), 0))), out.Get("Status"), api.DisplayablePorts(ports), strings.Join(outNames, ","))
|
|
if *size {
|
|
if *size {
|
|
if out.GetInt("SizeRootFs") > 0 {
|
|
if out.GetInt("SizeRootFs") > 0 {
|
|
fmt.Fprintf(w, "%s (virtual %s)\n", utils.HumanSize(out.GetInt64("SizeRw")), utils.HumanSize(out.GetInt64("SizeRootFs")))
|
|
fmt.Fprintf(w, "%s (virtual %s)\n", utils.HumanSize(out.GetInt64("SizeRw")), utils.HumanSize(out.GetInt64("SizeRootFs")))
|
|
@@ -1399,7 +1433,8 @@ func (cli *DockerCli) CmdCommit(args ...string) error {
|
|
cmd := cli.Subcmd("commit", "[OPTIONS] CONTAINER [REPOSITORY[:TAG]]", "Create a new image from a container's changes")
|
|
cmd := cli.Subcmd("commit", "[OPTIONS] CONTAINER [REPOSITORY[:TAG]]", "Create a new image from a container's changes")
|
|
flComment := cmd.String([]string{"m", "-message"}, "", "Commit message")
|
|
flComment := cmd.String([]string{"m", "-message"}, "", "Commit message")
|
|
flAuthor := cmd.String([]string{"a", "#author", "-author"}, "", "Author (eg. \"John Hannibal Smith <hannibal@a-team.com>\"")
|
|
flAuthor := cmd.String([]string{"a", "#author", "-author"}, "", "Author (eg. \"John Hannibal Smith <hannibal@a-team.com>\"")
|
|
- flConfig := cmd.String([]string{"#run", "-run"}, "", "Config automatically applied when the image is run. "+`(ex: -run='{"Cmd": ["cat", "/world"], "PortSpecs": ["22"]}')`)
|
|
|
|
|
|
+ // FIXME: --run is deprecated, it will be replaced with inline Dockerfile commands.
|
|
|
|
+ flConfig := cmd.String([]string{"#run", "#-run"}, "", "this option is deprecated and will be removed in a future version in favor of inline Dockerfile-compatible commands")
|
|
if err := cmd.Parse(args); err != nil {
|
|
if err := cmd.Parse(args); err != nil {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
@@ -1419,6 +1454,13 @@ func (cli *DockerCli) CmdCommit(args ...string) error {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ //Check if the given image name can be resolved
|
|
|
|
+ if repository != "" {
|
|
|
|
+ if _, _, err := registry.ResolveRepositoryName(repository); err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
v := url.Values{}
|
|
v := url.Values{}
|
|
v.Set("container", name)
|
|
v.Set("container", name)
|
|
v.Set("repo", repository)
|
|
v.Set("repo", repository)
|
|
@@ -1548,7 +1590,7 @@ func (cli *DockerCli) CmdLogs(args ...string) error {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
|
|
|
|
- container := &Container{}
|
|
|
|
|
|
+ container := &api.Container{}
|
|
err = json.Unmarshal(body, container)
|
|
err = json.Unmarshal(body, container)
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
@@ -1585,7 +1627,7 @@ func (cli *DockerCli) CmdAttach(args ...string) error {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
|
|
|
|
- container := &Container{}
|
|
|
|
|
|
+ container := &api.Container{}
|
|
err = json.Unmarshal(body, container)
|
|
err = json.Unmarshal(body, container)
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
@@ -1614,7 +1656,7 @@ func (cli *DockerCli) CmdAttach(args ...string) error {
|
|
|
|
|
|
if *proxy && !container.Config.Tty {
|
|
if *proxy && !container.Config.Tty {
|
|
sigc := cli.forwardAllSignals(cmd.Arg(0))
|
|
sigc := cli.forwardAllSignals(cmd.Arg(0))
|
|
- defer utils.StopCatch(sigc)
|
|
|
|
|
|
+ defer signal.StopCatch(sigc)
|
|
}
|
|
}
|
|
|
|
|
|
if err := cli.hijack("POST", "/containers/"+cmd.Arg(0)+"/attach?"+v.Encode(), container.Config.Tty, in, cli.out, cli.err, nil); err != nil {
|
|
if err := cli.hijack("POST", "/containers/"+cmd.Arg(0)+"/attach?"+v.Encode(), container.Config.Tty, in, cli.out, cli.err, nil); err != nil {
|
|
@@ -1707,6 +1749,11 @@ func (cli *DockerCli) CmdTag(args ...string) error {
|
|
}
|
|
}
|
|
|
|
|
|
v := url.Values{}
|
|
v := url.Values{}
|
|
|
|
+
|
|
|
|
+ //Check if the given image name can be resolved
|
|
|
|
+ if _, _, err := registry.ResolveRepositoryName(repository); err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
v.Set("repo", repository)
|
|
v.Set("repo", repository)
|
|
v.Set("tag", tag)
|
|
v.Set("tag", tag)
|
|
|
|
|
|
@@ -1753,7 +1800,21 @@ func (cli *DockerCli) CmdRun(args ...string) error {
|
|
if containerIDFile, err = os.Create(hostConfig.ContainerIDFile); err != nil {
|
|
if containerIDFile, err = os.Create(hostConfig.ContainerIDFile); err != nil {
|
|
return fmt.Errorf("Failed to create the container ID file: %s", err)
|
|
return fmt.Errorf("Failed to create the container ID file: %s", err)
|
|
}
|
|
}
|
|
- defer containerIDFile.Close()
|
|
|
|
|
|
+ defer func() {
|
|
|
|
+ containerIDFile.Close()
|
|
|
|
+ var (
|
|
|
|
+ cidFileInfo os.FileInfo
|
|
|
|
+ err error
|
|
|
|
+ )
|
|
|
|
+ if cidFileInfo, err = os.Stat(hostConfig.ContainerIDFile); err != nil {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if cidFileInfo.Size() == 0 {
|
|
|
|
+ if err := os.Remove(hostConfig.ContainerIDFile); err != nil {
|
|
|
|
+ fmt.Printf("failed to remove CID file '%s': %s \n", hostConfig.ContainerIDFile, err)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }()
|
|
}
|
|
}
|
|
|
|
|
|
containerValues := url.Values{}
|
|
containerValues := url.Values{}
|
|
@@ -1818,7 +1879,7 @@ func (cli *DockerCli) CmdRun(args ...string) error {
|
|
|
|
|
|
if sigProxy {
|
|
if sigProxy {
|
|
sigc := cli.forwardAllSignals(runResult.Get("Id"))
|
|
sigc := cli.forwardAllSignals(runResult.Get("Id"))
|
|
- defer utils.StopCatch(sigc)
|
|
|
|
|
|
+ defer signal.StopCatch(sigc)
|
|
}
|
|
}
|
|
|
|
|
|
var (
|
|
var (
|
|
@@ -1996,7 +2057,9 @@ func (cli *DockerCli) CmdCp(args ...string) error {
|
|
}
|
|
}
|
|
|
|
|
|
func (cli *DockerCli) CmdSave(args ...string) error {
|
|
func (cli *DockerCli) CmdSave(args ...string) error {
|
|
- cmd := cli.Subcmd("save", "IMAGE", "Save an image to a tar archive (streamed to stdout)")
|
|
|
|
|
|
+ cmd := cli.Subcmd("save", "IMAGE", "Save an image to a tar archive (streamed to stdout by default)")
|
|
|
|
+ outfile := cmd.String([]string{"o", "-output"}, "", "Write to an file, instead of STDOUT")
|
|
|
|
+
|
|
if err := cmd.Parse(args); err != nil {
|
|
if err := cmd.Parse(args); err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
@@ -2006,8 +2069,18 @@ func (cli *DockerCli) CmdSave(args ...string) error {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ var (
|
|
|
|
+ output io.Writer = cli.out
|
|
|
|
+ err error
|
|
|
|
+ )
|
|
|
|
+ if *outfile != "" {
|
|
|
|
+ output, err = os.Create(*outfile)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+ }
|
|
image := cmd.Arg(0)
|
|
image := cmd.Arg(0)
|
|
- if err := cli.stream("GET", "/images/"+image+"/get", nil, cli.out, nil); err != nil {
|
|
|
|
|
|
+ if err := cli.stream("GET", "/images/"+image+"/get", nil, output, nil); err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
return nil
|
|
@@ -2015,6 +2088,8 @@ func (cli *DockerCli) CmdSave(args ...string) error {
|
|
|
|
|
|
func (cli *DockerCli) CmdLoad(args ...string) error {
|
|
func (cli *DockerCli) CmdLoad(args ...string) error {
|
|
cmd := cli.Subcmd("load", "", "Load an image from a tar archive on STDIN")
|
|
cmd := cli.Subcmd("load", "", "Load an image from a tar archive on STDIN")
|
|
|
|
+ infile := cmd.String([]string{"i", "-input"}, "", "Read from a tar archive file, instead of STDIN")
|
|
|
|
+
|
|
if err := cmd.Parse(args); err != nil {
|
|
if err := cmd.Parse(args); err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
@@ -2024,408 +2099,18 @@ func (cli *DockerCli) CmdLoad(args ...string) error {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
- if err := cli.stream("POST", "/images/load", cli.in, cli.out, nil); err != nil {
|
|
|
|
- return err
|
|
|
|
- }
|
|
|
|
- return nil
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-func (cli *DockerCli) call(method, path string, data interface{}, passAuthInfo bool) (io.ReadCloser, int, error) {
|
|
|
|
- params := bytes.NewBuffer(nil)
|
|
|
|
- if data != nil {
|
|
|
|
- if env, ok := data.(engine.Env); ok {
|
|
|
|
- if err := env.Encode(params); err != nil {
|
|
|
|
- return nil, -1, err
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- buf, err := json.Marshal(data)
|
|
|
|
- if err != nil {
|
|
|
|
- return nil, -1, err
|
|
|
|
- }
|
|
|
|
- if _, err := params.Write(buf); err != nil {
|
|
|
|
- return nil, -1, err
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- // fixme: refactor client to support redirect
|
|
|
|
- re := regexp.MustCompile("/+")
|
|
|
|
- path = re.ReplaceAllString(path, "/")
|
|
|
|
-
|
|
|
|
- req, err := http.NewRequest(method, fmt.Sprintf("/v%s%s", APIVERSION, path), params)
|
|
|
|
- if err != nil {
|
|
|
|
- return nil, -1, err
|
|
|
|
- }
|
|
|
|
- if passAuthInfo {
|
|
|
|
- cli.LoadConfigFile()
|
|
|
|
- // Resolve the Auth config relevant for this server
|
|
|
|
- authConfig := cli.configFile.ResolveAuthConfig(auth.IndexServerAddress())
|
|
|
|
- getHeaders := func(authConfig auth.AuthConfig) (map[string][]string, error) {
|
|
|
|
- buf, err := json.Marshal(authConfig)
|
|
|
|
- if err != nil {
|
|
|
|
- return nil, err
|
|
|
|
- }
|
|
|
|
- registryAuthHeader := []string{
|
|
|
|
- base64.URLEncoding.EncodeToString(buf),
|
|
|
|
- }
|
|
|
|
- return map[string][]string{"X-Registry-Auth": registryAuthHeader}, nil
|
|
|
|
- }
|
|
|
|
- if headers, err := getHeaders(authConfig); err == nil && headers != nil {
|
|
|
|
- for k, v := range headers {
|
|
|
|
- req.Header[k] = v
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- req.Header.Set("User-Agent", "Docker-Client/"+dockerversion.VERSION)
|
|
|
|
- req.Host = cli.addr
|
|
|
|
- if data != nil {
|
|
|
|
- req.Header.Set("Content-Type", "application/json")
|
|
|
|
- } else if method == "POST" {
|
|
|
|
- req.Header.Set("Content-Type", "plain/text")
|
|
|
|
- }
|
|
|
|
- dial, err := net.Dial(cli.proto, cli.addr)
|
|
|
|
- if err != nil {
|
|
|
|
- if strings.Contains(err.Error(), "connection refused") {
|
|
|
|
- return nil, -1, ErrConnectionRefused
|
|
|
|
- }
|
|
|
|
- return nil, -1, err
|
|
|
|
- }
|
|
|
|
- clientconn := httputil.NewClientConn(dial, nil)
|
|
|
|
- resp, err := clientconn.Do(req)
|
|
|
|
- if err != nil {
|
|
|
|
- clientconn.Close()
|
|
|
|
- if strings.Contains(err.Error(), "connection refused") {
|
|
|
|
- return nil, -1, ErrConnectionRefused
|
|
|
|
- }
|
|
|
|
- return nil, -1, err
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if resp.StatusCode < 200 || resp.StatusCode >= 400 {
|
|
|
|
- body, err := ioutil.ReadAll(resp.Body)
|
|
|
|
- if err != nil {
|
|
|
|
- return nil, -1, err
|
|
|
|
- }
|
|
|
|
- if len(body) == 0 {
|
|
|
|
- return nil, resp.StatusCode, fmt.Errorf("Error: request returned %s for API route and version %s, check if the server supports the requested API version", http.StatusText(resp.StatusCode), req.URL)
|
|
|
|
- }
|
|
|
|
- return nil, resp.StatusCode, fmt.Errorf("Error: %s", bytes.TrimSpace(body))
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- wrapper := utils.NewReadCloserWrapper(resp.Body, func() error {
|
|
|
|
- if resp != nil && resp.Body != nil {
|
|
|
|
- resp.Body.Close()
|
|
|
|
- }
|
|
|
|
- return clientconn.Close()
|
|
|
|
- })
|
|
|
|
- return wrapper, resp.StatusCode, nil
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-func (cli *DockerCli) stream(method, path string, in io.Reader, out io.Writer, headers map[string][]string) error {
|
|
|
|
- if (method == "POST" || method == "PUT") && in == nil {
|
|
|
|
- in = bytes.NewReader([]byte{})
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // fixme: refactor client to support redirect
|
|
|
|
- re := regexp.MustCompile("/+")
|
|
|
|
- path = re.ReplaceAllString(path, "/")
|
|
|
|
-
|
|
|
|
- req, err := http.NewRequest(method, fmt.Sprintf("/v%s%s", APIVERSION, path), in)
|
|
|
|
- if err != nil {
|
|
|
|
- return err
|
|
|
|
- }
|
|
|
|
- req.Header.Set("User-Agent", "Docker-Client/"+dockerversion.VERSION)
|
|
|
|
- req.Host = cli.addr
|
|
|
|
- if method == "POST" {
|
|
|
|
- req.Header.Set("Content-Type", "plain/text")
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if headers != nil {
|
|
|
|
- for k, v := range headers {
|
|
|
|
- req.Header[k] = v
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- dial, err := net.Dial(cli.proto, cli.addr)
|
|
|
|
- if err != nil {
|
|
|
|
- if strings.Contains(err.Error(), "connection refused") {
|
|
|
|
- return fmt.Errorf("Cannot connect to the Docker daemon. Is 'docker -d' running on this host?")
|
|
|
|
- }
|
|
|
|
- return err
|
|
|
|
- }
|
|
|
|
- clientconn := httputil.NewClientConn(dial, nil)
|
|
|
|
- resp, err := clientconn.Do(req)
|
|
|
|
- defer clientconn.Close()
|
|
|
|
- if err != nil {
|
|
|
|
- if strings.Contains(err.Error(), "connection refused") {
|
|
|
|
- return fmt.Errorf("Cannot connect to the Docker daemon. Is 'docker -d' running on this host?")
|
|
|
|
- }
|
|
|
|
- return err
|
|
|
|
- }
|
|
|
|
- defer resp.Body.Close()
|
|
|
|
-
|
|
|
|
- if resp.StatusCode < 200 || resp.StatusCode >= 400 {
|
|
|
|
- body, err := ioutil.ReadAll(resp.Body)
|
|
|
|
|
|
+ var (
|
|
|
|
+ input io.Reader = cli.in
|
|
|
|
+ err error
|
|
|
|
+ )
|
|
|
|
+ if *infile != "" {
|
|
|
|
+ input, err = os.Open(*infile)
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
- if len(body) == 0 {
|
|
|
|
- return fmt.Errorf("Error :%s", http.StatusText(resp.StatusCode))
|
|
|
|
- }
|
|
|
|
- return fmt.Errorf("Error: %s", bytes.TrimSpace(body))
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if MatchesContentType(resp.Header.Get("Content-Type"), "application/json") {
|
|
|
|
- return utils.DisplayJSONMessagesStream(resp.Body, out, cli.terminalFd, cli.isTerminal)
|
|
|
|
}
|
|
}
|
|
- if _, err := io.Copy(out, resp.Body); err != nil {
|
|
|
|
- return err
|
|
|
|
- }
|
|
|
|
- return nil
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-func (cli *DockerCli) hijack(method, path string, setRawTerminal bool, in io.ReadCloser, stdout, stderr io.Writer, started chan io.Closer) error {
|
|
|
|
- defer func() {
|
|
|
|
- if started != nil {
|
|
|
|
- close(started)
|
|
|
|
- }
|
|
|
|
- }()
|
|
|
|
- // fixme: refactor client to support redirect
|
|
|
|
- re := regexp.MustCompile("/+")
|
|
|
|
- path = re.ReplaceAllString(path, "/")
|
|
|
|
-
|
|
|
|
- req, err := http.NewRequest(method, fmt.Sprintf("/v%s%s", APIVERSION, path), nil)
|
|
|
|
- if err != nil {
|
|
|
|
|
|
+ if err := cli.stream("POST", "/images/load", input, cli.out, nil); err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
- req.Header.Set("User-Agent", "Docker-Client/"+dockerversion.VERSION)
|
|
|
|
- req.Header.Set("Content-Type", "plain/text")
|
|
|
|
- req.Host = cli.addr
|
|
|
|
-
|
|
|
|
- dial, err := net.Dial(cli.proto, cli.addr)
|
|
|
|
- if err != nil {
|
|
|
|
- if strings.Contains(err.Error(), "connection refused") {
|
|
|
|
- return fmt.Errorf("Cannot connect to the Docker daemon. Is 'docker -d' running on this host?")
|
|
|
|
- }
|
|
|
|
- return err
|
|
|
|
- }
|
|
|
|
- clientconn := httputil.NewClientConn(dial, nil)
|
|
|
|
- defer clientconn.Close()
|
|
|
|
-
|
|
|
|
- // Server hijacks the connection, error 'connection closed' expected
|
|
|
|
- clientconn.Do(req)
|
|
|
|
-
|
|
|
|
- rwc, br := clientconn.Hijack()
|
|
|
|
- defer rwc.Close()
|
|
|
|
-
|
|
|
|
- if started != nil {
|
|
|
|
- started <- rwc
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- var receiveStdout chan error
|
|
|
|
-
|
|
|
|
- var oldState *term.State
|
|
|
|
-
|
|
|
|
- if in != nil && setRawTerminal && cli.isTerminal && os.Getenv("NORAW") == "" {
|
|
|
|
- oldState, err = term.SetRawTerminal(cli.terminalFd)
|
|
|
|
- if err != nil {
|
|
|
|
- return err
|
|
|
|
- }
|
|
|
|
- defer term.RestoreTerminal(cli.terminalFd, oldState)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if stdout != nil || stderr != nil {
|
|
|
|
- receiveStdout = utils.Go(func() (err error) {
|
|
|
|
- defer func() {
|
|
|
|
- if in != nil {
|
|
|
|
- if setRawTerminal && cli.isTerminal {
|
|
|
|
- term.RestoreTerminal(cli.terminalFd, oldState)
|
|
|
|
- }
|
|
|
|
- in.Close()
|
|
|
|
- }
|
|
|
|
- }()
|
|
|
|
-
|
|
|
|
- // When TTY is ON, use regular copy
|
|
|
|
- if setRawTerminal {
|
|
|
|
- _, err = io.Copy(stdout, br)
|
|
|
|
- } else {
|
|
|
|
- _, err = utils.StdCopy(stdout, stderr, br)
|
|
|
|
- }
|
|
|
|
- utils.Debugf("[hijack] End of stdout")
|
|
|
|
- return err
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- sendStdin := utils.Go(func() error {
|
|
|
|
- if in != nil {
|
|
|
|
- io.Copy(rwc, in)
|
|
|
|
- utils.Debugf("[hijack] End of stdin")
|
|
|
|
- }
|
|
|
|
- if tcpc, ok := rwc.(*net.TCPConn); ok {
|
|
|
|
- if err := tcpc.CloseWrite(); err != nil {
|
|
|
|
- utils.Errorf("Couldn't send EOF: %s\n", err)
|
|
|
|
- }
|
|
|
|
- } else if unixc, ok := rwc.(*net.UnixConn); ok {
|
|
|
|
- if err := unixc.CloseWrite(); err != nil {
|
|
|
|
- utils.Errorf("Couldn't send EOF: %s\n", err)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- // Discard errors due to pipe interruption
|
|
|
|
- return nil
|
|
|
|
- })
|
|
|
|
-
|
|
|
|
- if stdout != nil || stderr != nil {
|
|
|
|
- if err := <-receiveStdout; err != nil {
|
|
|
|
- utils.Errorf("Error receiveStdout: %s", err)
|
|
|
|
- return err
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if !cli.isTerminal {
|
|
|
|
- if err := <-sendStdin; err != nil {
|
|
|
|
- utils.Errorf("Error sendStdin: %s", err)
|
|
|
|
- return err
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
return nil
|
|
return nil
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-func (cli *DockerCli) getTtySize() (int, int) {
|
|
|
|
- if !cli.isTerminal {
|
|
|
|
- return 0, 0
|
|
|
|
- }
|
|
|
|
- ws, err := term.GetWinsize(cli.terminalFd)
|
|
|
|
- if err != nil {
|
|
|
|
- utils.Errorf("Error getting size: %s", err)
|
|
|
|
- if ws == nil {
|
|
|
|
- return 0, 0
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return int(ws.Height), int(ws.Width)
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-func (cli *DockerCli) resizeTty(id string) {
|
|
|
|
- height, width := cli.getTtySize()
|
|
|
|
- if height == 0 && width == 0 {
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- v := url.Values{}
|
|
|
|
- v.Set("h", strconv.Itoa(height))
|
|
|
|
- v.Set("w", strconv.Itoa(width))
|
|
|
|
- if _, _, err := readBody(cli.call("POST", "/containers/"+id+"/resize?"+v.Encode(), nil, false)); err != nil {
|
|
|
|
- utils.Errorf("Error resize: %s", err)
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-func (cli *DockerCli) monitorTtySize(id string) error {
|
|
|
|
- cli.resizeTty(id)
|
|
|
|
-
|
|
|
|
- sigchan := make(chan os.Signal, 1)
|
|
|
|
- signal.Notify(sigchan, syscall.SIGWINCH)
|
|
|
|
- go func() {
|
|
|
|
- for _ = range sigchan {
|
|
|
|
- cli.resizeTty(id)
|
|
|
|
- }
|
|
|
|
- }()
|
|
|
|
- return nil
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-func (cli *DockerCli) Subcmd(name, signature, description string) *flag.FlagSet {
|
|
|
|
- flags := flag.NewFlagSet(name, flag.ContinueOnError)
|
|
|
|
- flags.Usage = func() {
|
|
|
|
- fmt.Fprintf(cli.err, "\nUsage: docker %s %s\n\n%s\n\n", name, signature, description)
|
|
|
|
- flags.PrintDefaults()
|
|
|
|
- os.Exit(2)
|
|
|
|
- }
|
|
|
|
- return flags
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-func (cli *DockerCli) LoadConfigFile() (err error) {
|
|
|
|
- cli.configFile, err = auth.LoadConfig(os.Getenv("HOME"))
|
|
|
|
- if err != nil {
|
|
|
|
- fmt.Fprintf(cli.err, "WARNING: %s\n", err)
|
|
|
|
- }
|
|
|
|
- return err
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-func waitForExit(cli *DockerCli, containerId string) (int, error) {
|
|
|
|
- stream, _, err := cli.call("POST", "/containers/"+containerId+"/wait", nil, false)
|
|
|
|
- if err != nil {
|
|
|
|
- return -1, err
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- var out engine.Env
|
|
|
|
- if err := out.Decode(stream); err != nil {
|
|
|
|
- return -1, err
|
|
|
|
- }
|
|
|
|
- return out.GetInt("StatusCode"), nil
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// getExitCode perform an inspect on the container. It returns
|
|
|
|
-// the running state and the exit code.
|
|
|
|
-func getExitCode(cli *DockerCli, containerId string) (bool, int, error) {
|
|
|
|
- body, _, err := readBody(cli.call("GET", "/containers/"+containerId+"/json", nil, false))
|
|
|
|
- if err != nil {
|
|
|
|
- // If we can't connect, then the daemon probably died.
|
|
|
|
- if err != ErrConnectionRefused {
|
|
|
|
- return false, -1, err
|
|
|
|
- }
|
|
|
|
- return false, -1, nil
|
|
|
|
- }
|
|
|
|
- c := &Container{}
|
|
|
|
- if err := json.Unmarshal(body, c); err != nil {
|
|
|
|
- return false, -1, err
|
|
|
|
- }
|
|
|
|
- return c.State.Running, c.State.ExitCode, nil
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-func readBody(stream io.ReadCloser, statusCode int, err error) ([]byte, int, error) {
|
|
|
|
- if stream != nil {
|
|
|
|
- defer stream.Close()
|
|
|
|
- }
|
|
|
|
- if err != nil {
|
|
|
|
- return nil, statusCode, err
|
|
|
|
- }
|
|
|
|
- body, err := ioutil.ReadAll(stream)
|
|
|
|
- if err != nil {
|
|
|
|
- return nil, -1, err
|
|
|
|
- }
|
|
|
|
- return body, statusCode, nil
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-func NewDockerCli(in io.ReadCloser, out, err io.Writer, proto, addr string) *DockerCli {
|
|
|
|
- var (
|
|
|
|
- isTerminal = false
|
|
|
|
- terminalFd uintptr
|
|
|
|
- )
|
|
|
|
-
|
|
|
|
- if in != nil {
|
|
|
|
- if file, ok := in.(*os.File); ok {
|
|
|
|
- terminalFd = file.Fd()
|
|
|
|
- isTerminal = term.IsTerminal(terminalFd)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if err == nil {
|
|
|
|
- err = out
|
|
|
|
- }
|
|
|
|
- return &DockerCli{
|
|
|
|
- proto: proto,
|
|
|
|
- addr: addr,
|
|
|
|
- in: in,
|
|
|
|
- out: out,
|
|
|
|
- err: err,
|
|
|
|
- isTerminal: isTerminal,
|
|
|
|
- terminalFd: terminalFd,
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-type DockerCli struct {
|
|
|
|
- proto string
|
|
|
|
- addr string
|
|
|
|
- configFile *auth.ConfigFile
|
|
|
|
- in io.ReadCloser
|
|
|
|
- out io.Writer
|
|
|
|
- err io.Writer
|
|
|
|
- isTerminal bool
|
|
|
|
- terminalFd uintptr
|
|
|
|
}
|
|
}
|