Update readme and add TODO
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
parent
d84feb8fe5
commit
3a97fe27d8
|
@ -1,39 +1,34 @@
|
|||
## 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
|
||||
|
||||
First setup a container configuration. You will need a root fs, better go the path to a
|
||||
stopped docker container and use that.
|
||||
|
||||
#### container
|
||||
A container is a self contained directory that is able to run one or more processes inside without
|
||||
affecting the host system. The directory is usually a full system tree. Inside the directory
|
||||
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
|
||||
{
|
||||
"id": "koye",
|
||||
"namespace_pid": 12265,
|
||||
"command": {
|
||||
"args": [
|
||||
"/bin/bash"
|
||||
],
|
||||
"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": "",
|
||||
"hostname": "koye",
|
||||
"environment": [
|
||||
"HOME=/",
|
||||
"PATH=PATH=$PATH:/bin:/usr/bin:/sbin:/usr/sbin",
|
||||
"container=docker",
|
||||
"TERM=xterm-256color"
|
||||
],
|
||||
"namespaces": [
|
||||
"NEWNET",
|
||||
"NEWIPC",
|
||||
"NEWNS",
|
||||
"NEWPID",
|
||||
"NEWUTS"
|
||||
"NEWUTS",
|
||||
"NEWNET"
|
||||
],
|
||||
"capabilities": [
|
||||
"SETPCAP",
|
||||
|
@ -50,14 +45,32 @@ stopped docker container and use that.
|
|||
"AUDIT_CONTROL",
|
||||
"MAC_OVERRIDE",
|
||||
"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:
|
||||
`./cli exec container.json`
|
||||
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
|
||||
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
|
||||
file with the container still running and do:
|
||||
`./cli execin container.json`
|
||||
#### nsinit
|
||||
|
||||
`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.
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue