Update readme and add TODO

Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
Michael Crosby 2014-02-19 21:15:44 -08:00
parent bb59129b2f
commit 3ded9b431a
2 changed files with 61 additions and 31 deletions

View file

@ -1,39 +1,34 @@
## libcontainer - reference implementation for containers ## libcontainer - reference implementation for containers
#### playground #### background
libcontainer specifies configuration options for what a container is. It provides a native Go implementation
for using linux namespaces with no external dependencies. libcontainer provides many convience functions for working with namespaces, networking, and management.
Use the cli package to test out functionality #### container
A container is a self contained directory that is able to run one or more processes inside without
First setup a container configuration. You will need a root fs, better go the path to a affecting the host system. The directory is usually a full system tree. Inside the directory
stopped docker container and use that. a `container.json` file just be placed with the runtime configuration for how the process
should be contained and run. Environment, networking, and different capabilities for the
process are specified in this file.
Sample `container.json` file:
```json ```json
{ {
"id": "koye", "hostname": "koye",
"namespace_pid": 12265, "environment": [
"command": { "HOME=/",
"args": [ "PATH=PATH=$PATH:/bin:/usr/bin:/sbin:/usr/sbin",
"/bin/bash" "container=docker",
], "TERM=xterm-256color"
"environment": [ ],
"HOME=/",
"PATH=PATH=$PATH:/bin:/usr/bin:/sbin:/usr/sbin",
"container=docker",
"TERM=xterm"
]
},
"rootfs": "/root/development/gocode/src/github.com/docker/libcontainer/namespaces/ubuntu",
"network": null,
"user": "",
"working_dir": "",
"namespaces": [ "namespaces": [
"NEWNET",
"NEWIPC", "NEWIPC",
"NEWNS", "NEWNS",
"NEWPID", "NEWPID",
"NEWUTS" "NEWUTS",
"NEWNET"
], ],
"capabilities": [ "capabilities": [
"SETPCAP", "SETPCAP",
@ -50,14 +45,32 @@ stopped docker container and use that.
"AUDIT_CONTROL", "AUDIT_CONTROL",
"MAC_OVERRIDE", "MAC_OVERRIDE",
"MAC_ADMIN" "MAC_ADMIN"
] ],
"network": {
"ip": "172.17.0.100/16",
"gateway": "172.17.42.1",
"bridge": "docker0",
"mtu": 1500
}
} }
``` ```
After you have a json file and a rootfs path to use just run: 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
`./cli exec container.json` 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.
If you want to attach to an existing namespace just use the same json #### nsinit
file with the container still running and do:
`./cli execin container.json` `nsinit` is a cli application used as the reference implementation of libcontainer. It is able to
spawn or join new containers giving the current directory. To use `nsinit` cd into a linux
rootfs and copy a `container.json` file into the directory with your specified configuration.
To execution `/bin/bash` in the current directory as a container just run:
```bash
nsinit exec /bin/bash
```
If you wish to spawn another process inside the container while your current bash session is
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.
You can identify if a process is running in a container by looking to see if `.nspid` is in the root of the directory.

17
libcontainer/TODO.md Normal file
View file

@ -0,0 +1,17 @@
#### goals
* small and simple - line count is not everything but less code is better
* clean lines between what we do in the pkg
* provide primitives for working with namespaces not cater to every option
* 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
#### tasks
* proper tty for a new process in an existing container
* use exec or raw syscalls for new process in existing container
* setup proper user in namespace if specified
* implement hook or clean interface for cgroups
* example configs for different setups (host networking, boot init)
* improve pkg documentation with comments
* testing - this is hard in a low level pkg but we could do some, maybe
* pivot root
* selinux
* apparmor