Browse code

Update readme and add TODO Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)

Michael Crosby authored on 2014/02/20 14:15:44
Showing 2 changed files
... ...
@@ -1,39 +1,34 @@
1 1
 ## libcontainer - reference implementation for containers
2 2
 
3
-#### playground
3
+#### background
4 4
 
5
+libcontainer specifies configuration options for what a container is.  It provides a native Go implementation 
6
+for using linux namespaces with no external dependencies.  libcontainer provides many convience functions for working with namespaces, networking, and management.  
5 7
 
6
-Use the cli package to test out functionality
7
-
8
-First setup a container configuration.  You will need a root fs, better go the path to a
9
-stopped docker container and use that.
10 8
 
9
+#### container
10
+A container is a self contained directory that is able to run one or more processes inside without 
11
+affecting the host system.  The directory is usually a full system tree.  Inside the directory
12
+a `container.json` file just be placed with the runtime configuration for how the process 
13
+should be contained and run.  Environment, networking, and different capabilities for the 
14
+process are specified in this file.
11 15
 
16
+Sample `container.json` file:
12 17
 ```json
13 18
 {
14
-    "id": "koye",
15
-    "namespace_pid": 12265,
16
-    "command": {
17
-        "args": [
18
-            "/bin/bash"
19
-        ],
20
-        "environment": [
21
-            "HOME=/",
22
-            "PATH=PATH=$PATH:/bin:/usr/bin:/sbin:/usr/sbin",
23
-            "container=docker",
24
-            "TERM=xterm"
25
-        ]
26
-    },
27
-    "rootfs": "/root/development/gocode/src/github.com/docker/libcontainer/namespaces/ubuntu",
28
-    "network": null,
29
-    "user": "",
30
-    "working_dir": "",
19
+    "hostname": "koye",
20
+    "environment": [
21
+        "HOME=/",
22
+        "PATH=PATH=$PATH:/bin:/usr/bin:/sbin:/usr/sbin",
23
+        "container=docker",
24
+        "TERM=xterm-256color"
25
+    ],
31 26
     "namespaces": [
32
-        "NEWNET",
33 27
         "NEWIPC",
34 28
         "NEWNS",
35 29
         "NEWPID",
36
-        "NEWUTS"
30
+        "NEWUTS",
31
+        "NEWNET"
37 32
     ],
38 33
     "capabilities": [
39 34
         "SETPCAP",
... ...
@@ -50,14 +45,32 @@ stopped docker container and use that.
50 50
         "AUDIT_CONTROL",
51 51
         "MAC_OVERRIDE",
52 52
         "MAC_ADMIN"
53
-    ]
53
+    ],
54
+    "network": {
55
+        "ip": "172.17.0.100/16",
56
+        "gateway": "172.17.42.1",
57
+        "bridge": "docker0",
58
+        "mtu": 1500
59
+    }
54 60
 }
55 61
 ```
56 62
 
57
-After you have a json file and a rootfs path to use just run:
58
-`./cli exec container.json`
63
+Using this configuration and the current directory holding the rootfs for a process to live, one can se libcontainer to exec the container. Running the life of the namespace a `.nspid` file 
64
+is written to the current directory with the pid of the namespace'd process to the external word.  A client can use this pid to wait, kill, or perform other operation with the container.  If a user tries to run an new process inside an existing container with a live namespace with namespace will be joined by the new process.
65
+
66
+
67
+#### nsinit
68
+
69
+`nsinit` is a cli application used as the reference implementation of libcontainer.  It is able to 
70
+spawn or join new containers giving the current directory.  To use `nsinit` cd into a linux 
71
+rootfs and copy a `container.json` file into the directory with your specified configuration.
72
+
73
+To execution `/bin/bash` in the current directory as a container just run:
74
+```bash
75
+nsinit exec /bin/bash
76
+```
59 77
 
78
+If you wish to spawn another process inside the container while your current bash session is 
79
+running just run the exact same command again to get another bash shell or change the command.  If the original process dies, PID 1, all other processes spawned inside the container will also be killed and the namespace will be removed. 
60 80
 
61
-If you want to attach to an existing namespace just use the same json
62
-file with the container still running and do:
63
-`./cli execin container.json`
81
+You can identify if a process is running in a container by looking to see if `.nspid` is in the root of the directory.   
64 82
new file mode 100644
... ...
@@ -0,0 +1,17 @@
0
+#### goals
1
+* small and simple - line count is not everything but less code is better
2
+* clean lines between what we do in the pkg 
3
+* provide primitives for working with namespaces not cater to every option
4
+* extend via configuration not by features - host networking, no networking, veth network can be accomplished via adjusting the container.json, nothing to do with code
5
+
6
+#### tasks
7
+* proper tty for a new process in an existing container
8
+* use exec or raw syscalls for new process in existing container
9
+* setup proper user in namespace if specified
10
+* implement hook or clean interface for cgroups
11
+* example configs for different setups (host networking, boot init)
12
+* improve pkg documentation with comments
13
+* testing - this is hard in a low level pkg but we could do some, maybe
14
+* pivot root
15
+* selinux
16
+* apparmor