• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

contrib/H30-Sep-2019-

docs/H30-Sep-2019-

libcontainer/H30-Sep-2019-

man/H30-Sep-2019-

script/H30-Sep-2019-

tests/H30-Sep-2019-

vendor/H30-Sep-2019-

.gitignoreH A D30-Sep-201970

.pullapprove.ymlH A D30-Sep-2019188

.travis.ymlH A D30-Sep-2019807

CONTRIBUTING.mdH A D30-Sep-20195.1 KiB

DockerfileH A D30-Sep-20192 KiB

LICENSEH A D30-Sep-201910.5 KiB

MAINTAINERSH A D30-Sep-2019237

MAINTAINERS_GUIDE.mdH A D30-Sep-20195.4 KiB

MakefileH A D30-Sep-20195.1 KiB

NOTICEH A D30-Sep-2019518

PRINCIPLES.mdH A D30-Sep-20191.1 KiB

README.mdH A D30-Sep-20199.3 KiB

VERSIONH A D30-Sep-201910

checkpoint.goH A D30-Sep-20194.7 KiB

create.goH A D30-Sep-20192.3 KiB

delete.goH A D30-Sep-20192.3 KiB

events.goH A D30-Sep-20199.4 KiB

exec.goH A D30-Sep-20196.1 KiB

init.goH A D30-Sep-20191.3 KiB

kill.goH A D30-Sep-20191.5 KiB

list.goH A D30-Sep-20194.5 KiB

main.goH A D30-Sep-20194.6 KiB

notify_socket.goH A D30-Sep-20192.4 KiB

pause.goH A D30-Sep-20191.7 KiB

ps.goH A D30-Sep-20192.2 KiB

restore.goH A D30-Sep-20194 KiB

rlimit_linux.goH A D30-Sep-20191.6 KiB

rootless_linux.goH A D30-Sep-20191.3 KiB

run.goH A D30-Sep-20192.5 KiB

signalmap.goH A D30-Sep-20191,010

signalmap_mipsx.goH A D30-Sep-2019987

signals.goH A D30-Sep-20193.5 KiB

spec.goH A D30-Sep-20194.3 KiB

start.goH A D30-Sep-20191.1 KiB

state.goH A D30-Sep-20191.4 KiB

tty.goH A D30-Sep-20193.6 KiB

update.goH A D30-Sep-20197.7 KiB

utils.goH A D30-Sep-20192.1 KiB

utils_linux.goH A D30-Sep-201912 KiB

vendor.confH A D30-Sep-20191.8 KiB

README.md

1# runc
2
3[![Build Status](https://travis-ci.org/opencontainers/runc.svg?branch=master)](https://travis-ci.org/opencontainers/runc)
4[![Go Report Card](https://goreportcard.com/badge/github.com/opencontainers/runc)](https://goreportcard.com/report/github.com/opencontainers/runc)
5[![GoDoc](https://godoc.org/github.com/opencontainers/runc?status.svg)](https://godoc.org/github.com/opencontainers/runc)
6
7## Introduction
8
9`runc` is a CLI tool for spawning and running containers according to the OCI specification.
10
11## Releases
12
13`runc` depends on and tracks the [runtime-spec](https://github.com/opencontainers/runtime-spec) repository.
14We will try to make sure that `runc` and the OCI specification major versions stay in lockstep.
15This means that `runc` 1.0.0 should implement the 1.0 version of the specification.
16
17You can find official releases of `runc` on the [release](https://github.com/opencontainers/runc/releases) page.
18
19## Security
20
21Reporting process and disclosure communications are outlined in [/org/security](https://github.com/opencontainers/org/blob/master/security/)
22
23## Building
24
25`runc` currently supports the Linux platform with various architecture support.
26It must be built with Go version 1.6 or higher in order for some features to function properly.
27
28In order to enable seccomp support you will need to install `libseccomp` on your platform.
29> e.g. `libseccomp-devel` for CentOS, or `libseccomp-dev` for Ubuntu
30
31Otherwise, if you do not want to build `runc` with seccomp support you can add `BUILDTAGS=""` when running make.
32
33```bash
34# create a 'github.com/opencontainers' in your GOPATH/src
35cd github.com/opencontainers
36git clone https://github.com/opencontainers/runc
37cd runc
38
39make
40sudo make install
41```
42
43You can also use `go get` to install to your `GOPATH`, assuming that you have a `github.com` parent folder already created under `src`:
44
45```bash
46go get github.com/opencontainers/runc
47cd $GOPATH/src/github.com/opencontainers/runc
48make
49sudo make install
50```
51
52`runc` will be installed to `/usr/local/sbin/runc` on your system.
53
54
55#### Build Tags
56
57`runc` supports optional build tags for compiling support of various features.
58To add build tags to the make option the `BUILDTAGS` variable must be set.
59
60```bash
61make BUILDTAGS='seccomp apparmor'
62```
63
64| Build Tag | Feature                            | Dependency  |
65|-----------|------------------------------------|-------------|
66| seccomp   | Syscall filtering                  | libseccomp  |
67| selinux   | selinux process and mount labeling | <none>      |
68| apparmor  | apparmor profile support           | <none>      |
69| ambient   | ambient capability support         | kernel 4.3  |
70| nokmem    | disable kernel memory account      | <none>      |
71
72
73### Running the test suite
74
75`runc` currently supports running its test suite via Docker.
76To run the suite just type `make test`.
77
78```bash
79make test
80```
81
82There are additional make targets for running the tests outside of a container but this is not recommended as the tests are written with the expectation that they can write and remove anywhere.
83
84You can run a specific test case by setting the `TESTFLAGS` variable.
85
86```bash
87# make test TESTFLAGS="-run=SomeTestFunction"
88```
89
90You can run a specific integration test by setting the `TESTPATH` variable.
91
92```bash
93# make test TESTPATH="/checkpoint.bats"
94```
95
96You can run a test in your proxy environment by setting `DOCKER_BUILD_PROXY` and `DOCKER_RUN_PROXY` variables.
97
98```bash
99# make test DOCKER_BUILD_PROXY="--build-arg HTTP_PROXY=http://yourproxy/" DOCKER_RUN_PROXY="-e HTTP_PROXY=http://yourproxy/"
100```
101
102### Dependencies Management
103
104`runc` uses [vndr](https://github.com/LK4D4/vndr) for dependencies management.
105Please refer to [vndr](https://github.com/LK4D4/vndr) for how to add or update
106new dependencies.
107
108## Using runc
109
110### Creating an OCI Bundle
111
112In order to use runc you must have your container in the format of an OCI bundle.
113If you have Docker installed you can use its `export` method to acquire a root filesystem from an existing Docker container.
114
115```bash
116# create the top most bundle directory
117mkdir /mycontainer
118cd /mycontainer
119
120# create the rootfs directory
121mkdir rootfs
122
123# export busybox via Docker into the rootfs directory
124docker export $(docker create busybox) | tar -C rootfs -xvf -
125```
126
127After a root filesystem is populated you just generate a spec in the format of a `config.json` file inside your bundle.
128`runc` provides a `spec` command to generate a base template spec that you are then able to edit.
129To find features and documentation for fields in the spec please refer to the [specs](https://github.com/opencontainers/runtime-spec) repository.
130
131```bash
132runc spec
133```
134
135### Running Containers
136
137Assuming you have an OCI bundle from the previous step you can execute the container in two different ways.
138
139The first way is to use the convenience command `run` that will handle creating, starting, and deleting the container after it exits.
140
141```bash
142# run as root
143cd /mycontainer
144runc run mycontainerid
145```
146
147If you used the unmodified `runc spec` template this should give you a `sh` session inside the container.
148
149The second way to start a container is using the specs lifecycle operations.
150This gives you more power over how the container is created and managed while it is running.
151This will also launch the container in the background so you will have to edit the `config.json` to remove the `terminal` setting for the simple examples here.
152Your process field in the `config.json` should look like this below with `"terminal": false` and `"args": ["sleep", "5"]`.
153
154
155```json
156        "process": {
157                "terminal": false,
158                "user": {
159                        "uid": 0,
160                        "gid": 0
161                },
162                "args": [
163                        "sleep", "5"
164                ],
165                "env": [
166                        "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
167                        "TERM=xterm"
168                ],
169                "cwd": "/",
170                "capabilities": {
171                        "bounding": [
172                                "CAP_AUDIT_WRITE",
173                                "CAP_KILL",
174                                "CAP_NET_BIND_SERVICE"
175                        ],
176                        "effective": [
177                                "CAP_AUDIT_WRITE",
178                                "CAP_KILL",
179                                "CAP_NET_BIND_SERVICE"
180                        ],
181                        "inheritable": [
182                                "CAP_AUDIT_WRITE",
183                                "CAP_KILL",
184                                "CAP_NET_BIND_SERVICE"
185                        ],
186                        "permitted": [
187                                "CAP_AUDIT_WRITE",
188                                "CAP_KILL",
189                                "CAP_NET_BIND_SERVICE"
190                        ],
191                        "ambient": [
192                                "CAP_AUDIT_WRITE",
193                                "CAP_KILL",
194                                "CAP_NET_BIND_SERVICE"
195                        ]
196                },
197                "rlimits": [
198                        {
199                                "type": "RLIMIT_NOFILE",
200                                "hard": 1024,
201                                "soft": 1024
202                        }
203                ],
204                "noNewPrivileges": true
205        },
206```
207
208Now we can go through the lifecycle operations in your shell.
209
210
211```bash
212# run as root
213cd /mycontainer
214runc create mycontainerid
215
216# view the container is created and in the "created" state
217runc list
218
219# start the process inside the container
220runc start mycontainerid
221
222# after 5 seconds view that the container has exited and is now in the stopped state
223runc list
224
225# now delete the container
226runc delete mycontainerid
227```
228
229This allows higher level systems to augment the containers creation logic with setup of various settings after the container is created and/or before it is deleted. For example, the container's network stack is commonly set up after `create` but before `start`.
230
231#### Rootless containers
232`runc` has the ability to run containers without root privileges. This is called `rootless`. You need to pass some parameters to `runc` in order to run rootless containers. See below and compare with the previous version. Run the following commands as an ordinary user:
233```bash
234# Same as the first example
235mkdir ~/mycontainer
236cd ~/mycontainer
237mkdir rootfs
238docker export $(docker create busybox) | tar -C rootfs -xvf -
239
240# The --rootless parameter instructs runc spec to generate a configuration for a rootless container, which will allow you to run the container as a non-root user.
241runc spec --rootless
242
243# The --root parameter tells runc where to store the container state. It must be writable by the user.
244runc --root /tmp/runc run mycontainerid
245```
246
247#### Supervisors
248
249`runc` can be used with process supervisors and init systems to ensure that containers are restarted when they exit.
250An example systemd unit file looks something like this.
251
252```systemd
253[Unit]
254Description=Start My Container
255
256[Service]
257Type=forking
258ExecStart=/usr/local/sbin/runc run -d --pid-file /run/mycontainerid.pid mycontainerid
259ExecStopPost=/usr/local/sbin/runc delete mycontainerid
260WorkingDirectory=/mycontainer
261PIDFile=/run/mycontainerid.pid
262
263[Install]
264WantedBy=multi-user.target
265```
266
267## License
268
269The code and docs are released under the [Apache 2.0 license](LICENSE).
270