Browse Source

Merge pull request #4721 from vieux/4716-display_ps-fix

Fix display command display in docker ps
unclejack 11 years ago
parent
commit
0e92c7c24a
2 changed files with 13 additions and 1 deletions
  1. 12 0
      runtime/container.go
  2. 1 1
      server/server.go

+ 12 - 0
runtime/container.go

@@ -402,6 +402,18 @@ func populateCommand(c *Container) {
 	c.command.SysProcAttr = &syscall.SysProcAttr{Setsid: true}
 }
 
+func (container *Container) ArgsAsString() string {
+	var args []string
+	for _, arg := range container.Args {
+		if strings.Contains(arg, " ") {
+			args = append(args, fmt.Sprintf("'%s'", arg))
+		} else {
+			args = append(args, arg)
+		}
+	}
+	return strings.Join(args, " ")
+}
+
 func (container *Container) Start() (err error) {
 	container.Lock()
 	defer container.Unlock()

+ 1 - 1
server/server.go

@@ -1003,7 +1003,7 @@ func (srv *Server) Containers(job *engine.Job) engine.Status {
 		out.SetList("Names", names[container.ID])
 		out.Set("Image", srv.runtime.Repositories().ImageName(container.Image))
 		if len(container.Args) > 0 {
-			out.Set("Command", fmt.Sprintf("\"%s %s\"", container.Path, strings.Join(container.Args, " ")))
+			out.Set("Command", fmt.Sprintf("\"%s %s\"", container.Path, container.ArgsAsString()))
 		} else {
 			out.Set("Command", fmt.Sprintf("\"%s\"", container.Path))
 		}