2016-01-23 03:44:52 +08:00
|
|
|
[![Build Status](https://jenkins.dockerproject.org/buildStatus/icon?job=runc Master)](https://jenkins.dockerproject.org/job/runc Master)
|
|
|
|
|
2015-06-22 10:31:12 +08:00
|
|
|
## runc
|
|
|
|
|
2016-04-14 01:38:58 +08:00
|
|
|
`runc` is a CLI tool for spawning and running containers according to the OCI specification.
|
2015-06-22 10:31:12 +08:00
|
|
|
|
2015-06-27 02:31:00 +08:00
|
|
|
## State of the project
|
|
|
|
|
2015-09-02 00:32:29 +08:00
|
|
|
Currently `runc` is an implementation of the OCI specification. We are currently sprinting
|
2015-12-11 09:11:17 +08:00
|
|
|
to have a v1 of the spec out. So the `runc` config format will be constantly changing until
|
|
|
|
the spec is finalized. However, we encourage you to try out the tool and give feedback.
|
2015-06-27 02:31:00 +08:00
|
|
|
|
2016-05-28 16:58:17 +08:00
|
|
|
### OCI
|
2015-07-03 00:59:30 +08:00
|
|
|
|
2015-09-02 00:32:29 +08:00
|
|
|
How does `runc` integrate with the Open Container Initiative Specification?
|
|
|
|
`runc` depends on the types specified in the
|
2016-04-13 04:35:51 +08:00
|
|
|
[specs](https://github.com/opencontainers/runtime-spec) repository. Whenever the
|
2015-09-02 00:32:29 +08:00
|
|
|
specification is updated and ready to be versioned `runc` will update its dependency
|
2015-07-03 00:59:30 +08:00
|
|
|
on the specs repository and support the update spec.
|
|
|
|
|
2015-06-22 10:31:12 +08:00
|
|
|
### Building:
|
|
|
|
|
2015-08-27 15:50:46 +08:00
|
|
|
At the time of writing, runc only builds on the Linux platform.
|
|
|
|
|
2015-06-22 10:31:12 +08:00
|
|
|
```bash
|
2015-07-08 19:10:22 +08:00
|
|
|
# create a 'github.com/opencontainers' in your GOPATH/src
|
2015-06-24 12:25:49 +08:00
|
|
|
cd github.com/opencontainers
|
|
|
|
git clone https://github.com/opencontainers/runc
|
|
|
|
cd runc
|
2015-06-22 10:31:12 +08:00
|
|
|
make
|
|
|
|
sudo make install
|
|
|
|
```
|
|
|
|
|
2015-08-22 06:25:26 +08:00
|
|
|
In order to enable seccomp support you will need to install libseccomp on your platform.
|
2016-04-06 22:11:28 +08:00
|
|
|
If you do not want to build `runc` with seccomp support you can add `BUILDTAGS=""` when running make.
|
2015-08-22 06:25:26 +08:00
|
|
|
|
2015-09-12 03:11:24 +08:00
|
|
|
#### Build Tags
|
|
|
|
|
|
|
|
`runc` supports optional build tags for compiling in support for various features.
|
|
|
|
|
|
|
|
|
|
|
|
| Build Tag | Feature | Dependency |
|
|
|
|
|-----------|------------------------------------|-------------|
|
|
|
|
| seccomp | Syscall filtering | libseccomp |
|
|
|
|
| selinux | selinux process and mount labeling | <none> |
|
|
|
|
| apparmor | apparmor profile support | libapparmor |
|
|
|
|
|
2015-09-15 08:30:28 +08:00
|
|
|
### Testing:
|
|
|
|
|
|
|
|
You can run tests for runC by using command:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
# make test
|
|
|
|
```
|
|
|
|
|
|
|
|
Note that test cases are run in Docker container, so you need to install
|
|
|
|
`docker` first. And test requires mounting cgroups inside container, it's
|
|
|
|
done by docker now, so you need a docker version newer than 1.8.0-rc2.
|
|
|
|
|
|
|
|
You can also run specific test cases by:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
# make test TESTFLAGS="-run=SomeTestFunction"
|
|
|
|
```
|
2015-09-12 03:11:24 +08:00
|
|
|
|
2015-06-22 10:31:12 +08:00
|
|
|
### Using:
|
|
|
|
|
2016-02-09 06:25:03 +08:00
|
|
|
To run a container with the id "test", execute `runc start` with the containers id as arg one
|
|
|
|
in the bundle's root directory:
|
|
|
|
|
2015-08-18 09:30:17 +08:00
|
|
|
```bash
|
2016-02-09 06:25:03 +08:00
|
|
|
runc start test
|
2015-08-18 09:30:17 +08:00
|
|
|
/ $ ps
|
|
|
|
PID USER COMMAND
|
|
|
|
1 daemon sh
|
|
|
|
5 daemon sh
|
|
|
|
/ $
|
|
|
|
```
|
2015-06-22 10:31:12 +08:00
|
|
|
|
2015-09-02 00:32:29 +08:00
|
|
|
### OCI Container JSON Format:
|
2015-06-22 10:31:12 +08:00
|
|
|
|
2016-04-13 04:35:51 +08:00
|
|
|
OCI container JSON format is based on OCI [specs](https://github.com/opencontainers/runtime-spec).
|
2016-02-06 07:15:25 +08:00
|
|
|
You can generate JSON files by using `runc spec`.
|
|
|
|
It assumes that the file-system is found in a directory called
|
2015-10-27 15:34:38 +08:00
|
|
|
`rootfs` and there is a user with uid and gid of `0` defined within that file-system.
|
|
|
|
|
2015-06-22 10:31:12 +08:00
|
|
|
### Examples:
|
|
|
|
|
2015-06-29 15:08:16 +08:00
|
|
|
#### Using a Docker image (requires version 1.3 or later)
|
2015-06-24 12:25:49 +08:00
|
|
|
|
|
|
|
To test using Docker's `busybox` image follow these steps:
|
2015-06-29 08:47:00 +08:00
|
|
|
* Install `docker` and download the `busybox` image: `docker pull busybox`
|
2016-04-13 22:54:06 +08:00
|
|
|
* Create a container from that image and export its contents in a directory:
|
2015-06-24 12:25:49 +08:00
|
|
|
```
|
|
|
|
mkdir rootfs
|
2016-04-13 22:54:06 +08:00
|
|
|
docker export $(docker create busybox) | tar -C rootfs -xvf -
|
2015-06-24 12:25:49 +08:00
|
|
|
```
|
2016-02-06 07:15:25 +08:00
|
|
|
* Create `config.json` by using `runc spec`.
|
2015-08-18 09:30:17 +08:00
|
|
|
* Execute `runc start` and you should be placed into a shell where you can run `ps`:
|
2015-06-24 12:25:49 +08:00
|
|
|
```
|
2016-02-09 06:25:03 +08:00
|
|
|
$ runc start test
|
2015-06-24 12:25:49 +08:00
|
|
|
/ # ps
|
|
|
|
PID USER COMMAND
|
|
|
|
1 root sh
|
|
|
|
9 root ps
|
|
|
|
```
|
|
|
|
|
2015-06-22 10:31:12 +08:00
|
|
|
#### Using runc with systemd
|
|
|
|
|
2015-10-28 16:21:39 +08:00
|
|
|
To use runc with systemd, you can create a unit file
|
|
|
|
`/usr/lib/systemd/system/minecraft.service` as below (edit your
|
|
|
|
own Description or WorkingDirectory or service name as you need).
|
|
|
|
|
2015-06-22 10:31:12 +08:00
|
|
|
```service
|
|
|
|
[Unit]
|
|
|
|
Description=Minecraft Build Server
|
|
|
|
Documentation=http://minecraft.net
|
|
|
|
After=network.target
|
|
|
|
|
|
|
|
[Service]
|
|
|
|
CPUQuota=200%
|
|
|
|
MemoryLimit=1536M
|
2016-04-24 00:30:08 +08:00
|
|
|
ExecStart=/usr/local/sbin/runc start minecraft
|
2015-06-22 10:31:12 +08:00
|
|
|
Restart=on-failure
|
|
|
|
WorkingDirectory=/containers/minecraftbuild
|
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=multi-user.target
|
|
|
|
```
|
2015-10-28 16:21:39 +08:00
|
|
|
|
|
|
|
Make sure you have the bundle's root directory and JSON configs in
|
|
|
|
your WorkingDirectory, then use systemd commands to start the service:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
systemctl daemon-reload
|
|
|
|
systemctl start minecraft.service
|
|
|
|
```
|
|
|
|
|
|
|
|
Note that if you use JSON configs by `runc spec`, you need to modify
|
|
|
|
`config.json` and change `process.terminal` to false so runc won't
|
|
|
|
create tty, because we can't set terminal from the stdin when using
|
|
|
|
systemd service.
|