Browse code

Adding exec remote API documentation along with minor code cleanup. Docker-DCO-1.1-Signed-off-by: Vishnu Kannan <vishnuk@google.com> (github: vishh)

Vishnu Kannan authored on 2014/09/18 03:36:51
Showing 7 changed files
... ...
@@ -1088,6 +1088,7 @@ func postContainerExecCreate(eng *engine.Engine, version version.Version, w http
1088 1088
 	return writeJSON(w, http.StatusCreated, out)
1089 1089
 }
1090 1090
 
1091
+// TODO(vishh): Refactor the code to avoid having to specify stream config as part of both create and start.
1091 1092
 func postContainerExecStart(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
1092 1093
 	if err := parseForm(r); err != nil {
1093 1094
 		return nil
... ...
@@ -1144,6 +1145,7 @@ func postContainerExecStart(eng *engine.Engine, version version.Version, w http.
1144 1144
 		return err
1145 1145
 	}
1146 1146
 	w.WriteHeader(http.StatusNoContent)
1147
+
1147 1148
 	return nil
1148 1149
 }
1149 1150
 
... ...
@@ -78,7 +78,7 @@ func (d *Daemon) getExecConfig(name string) (*execConfig, error) {
78 78
 		return execConfig, nil
79 79
 	}
80 80
 
81
-	return nil, fmt.Errorf("No exec '%s' in found in daemon", name)
81
+	return nil, fmt.Errorf("No such exec instance '%s' found in daemon", name)
82 82
 }
83 83
 
84 84
 func (d *Daemon) unregisterExecCommand(execConfig *execConfig) {
... ...
@@ -2,7 +2,7 @@
2 2
 % Docker Community
3 3
 % SEPT 2014
4 4
 # NAME
5
-docker-exec - Run a command in an active container
5
+docker-exec - Run a command in a running container
6 6
 
7 7
 # SYNOPSIS
8 8
 **docker exec**
... ...
@@ -13,7 +13,7 @@ docker-exec - Run a command in an active container
13 13
 
14 14
 # DESCRIPTION
15 15
 
16
-Run a process in an existing container. The existing CONTAINER needs to be active.
16
+Run a process in a running container. 
17 17
 
18 18
 # Options
19 19
 
... ...
@@ -106,7 +106,7 @@ unix://[/path/to/socket] to use.
106 106
   Get real time events from the server
107 107
 
108 108
 **docker-exec(1)**
109
-  Run a command in an active container
109
+  Run a command in a running container
110 110
 
111 111
 **docker-export(1)**
112 112
   Stream the contents of a container as a tar archive
... ...
@@ -43,6 +43,16 @@ You can still call an old version of the API using
43 43
 **New!**
44 44
 Now has header: `Content-Type: application/x-json-stream`.
45 45
 
46
+`POST /containers/(id)/exec`
47
+
48
+**New!**
49
+Setup an exec command in a running container `id`.
50
+
51
+`POST /exec/(id)/start`
52
+
53
+**New!**
54
+Start an exec command.
55
+
46 56
 ## v1.14
47 57
 
48 58
 ### Full Documentation
... ...
@@ -1428,6 +1428,110 @@ the root that contains a list of repository and tag names mapped to layer IDs.
1428 1428
 }
1429 1429
 ```
1430 1430
 
1431
+### Exec Create
1432
+
1433
+`POST /containers/(id)/exec`
1434
+
1435
+Sets up an exec instance in a running container `id`
1436
+
1437
+**Example request**:
1438
+
1439
+        POST /containers/e90e34656806/exec HTTP/1.1
1440
+        Content-Type: application/json
1441
+
1442
+        {             
1443
+	     "Detach":false,
1444
+	     "AttachStdin":false,
1445
+	     "AttachStdout":true,
1446
+	     "AttachStderr":true,
1447
+	     "Tty":false,
1448
+	     "Cmd":[
1449
+                     "date"
1450
+             ],
1451
+	     "Container":"e90e34656806",
1452
+        }
1453
+
1454
+**Example response**:
1455
+
1456
+        HTTP/1.1 201 OK
1457
+        Content-Type: application/json
1458
+
1459
+        {
1460
+             "Id":"f90e34656806"
1461
+        }
1462
+
1463
+Json Parameters:
1464
+
1465
+-   **execConfig** ? exec configuration.
1466
+
1467
+Status Codes:
1468
+
1469
+-   **201** – no error
1470
+-   **404** – no such container
1471
+
1472
+### Exec Start
1473
+
1474
+`POST /exec/(id)/start`
1475
+
1476
+Starts a previously set up exec instance `id`. If `detach` is true, this API returns after
1477
+starting the `exec` command. Otherwise, this API sets up an interactive session with the `exec` command.
1478
+
1479
+**Example request**:
1480
+
1481
+        POST /containers/e90e34656806/exec HTTP/1.1
1482
+        Content-Type: application/json
1483
+
1484
+        {
1485
+	     "Detach":false,
1486
+	     "Tty":false,
1487
+        }
1488
+
1489
+**Example response**:
1490
+
1491
+        HTTP/1.1 201 OK
1492
+        Content-Type: application/json
1493
+
1494
+        {{ STREAM }}
1495
+
1496
+Json Parameters:
1497
+
1498
+-   **execConfig** ? exec configuration.
1499
+
1500
+Status Codes:
1501
+
1502
+-   **201** – no error
1503
+-   **404** – no such exec instance
1504
+
1505
+    **Stream details**:
1506
+    Similar to the stream behavior of `POST /container/(id)/attach` API
1507
+
1508
+### Exec Resize
1509
+
1510
+`POST /exec/(id)/resize`
1511
+
1512
+Resizes the tty session used by the exec command `id`.
1513
+This API is valid only if `tty` was specified as part of creating and starting the exec command.
1514
+
1515
+**Example request**:
1516
+
1517
+        POST /containers/e90e34656806/exec HTTP/1.1
1518
+        Content-Type: plain/text
1519
+
1520
+**Example response**:
1521
+
1522
+        HTTP/1.1 201 OK
1523
+        Content-Type: plain/text
1524
+
1525
+Query Parameters:
1526
+
1527
+-   **h** – height of tty session
1528
+-   **w** – width
1529
+
1530
+Status Codes:
1531
+
1532
+-   **201** – no error
1533
+-   **404** – no such exec instance
1534
+
1431 1535
 # 3. Going further
1432 1536
 
1433 1537
 ## 3.1 Inside `docker run`
... ...
@@ -555,25 +555,24 @@ You'll need two shells for this example.
555 555
       -i, --interactive=false    Keep STDIN open even if not attached
556 556
       -t, --tty=false            Allocate a pseudo-TTY
557 557
 
558
-The `docker exec` command runs a user specified command as a new process in an existing
559
-user specified container. The container needs to be active.
558
+The `docker exec` command runs a new command in a running container.
560 559
 
561
-The `docker exec` command will typically be used after `docker run`.
560
+The `docker exec` command will typically be used after `docker run` or `docker start`.
562 561
 
563 562
 ### Examples:
564 563
 
565 564
     $ sudo docker run --name ubuntu_bash --rm -i -t ubuntu bash
566 565
 
567
-This will create a container named 'ubuntu_bash' and start a bash session.
566
+This will create a container named `ubuntu_bash` and start a Bash session.
568 567
 
569 568
     $ sudo docker exec -d ubuntu_bash touch /tmp/execWorks
570 569
 
571
-This will create a new file '/tmp/execWorks' inside the existing and active container
572
-'ubuntu_bash', in the background.
570
+This will create a new file `/tmp/execWorks` inside the running container
571
+`ubuntu_bash`, in the background.
573 572
 
574 573
     $ sudo docker exec ubuntu_bash -it bash
575 574
 
576
-This will create a new bash session in the container 'ubuntu_bash'.
575
+This will create a new Bash session in the container `ubuntu_bash`.
577 576
 
578 577
 ## export
579 578