Runc: Difference between revisions

From Alpine Linux
(based on posting in https://irclogs.alpinelinux.org/%23alpine-linux-2025-07.log by user Donno at https://tpaste.us/gbvy)
 
m (fixed link name)
 
(10 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[https://github.com/opencontainers/runc Runc] is a CLI tool for spawning and running containers on Linux according to the OCI specification. This page provides instructions to setup containers using runc.
{{DISPLAYTITLE:runc}}[https://github.com/opencontainers/runc runc] is a CLI tool for spawning and running containers on Linux according to the OCI specification, implemented in Go. This page provides instructions to setup containers using runc.
{{Draft}}
 
== Set up a minimal container ==
The tool is meant as a low-level tool and is intended to deal with the plumbing of container. The expectaiton is is it is used by higher level container software (such as [[Docker]] and [[Podman]]) to provide an interface better suited at common tasks. However, it can be useful for learning how things work, small tests or building your own tooling.
 
== Prerequisites ==
 
* Enable [[OpenRC#cgroups|cgroups]]
 
== Installation ==
 
Install the {{pkg|runc}} package:{{Cmd|# apk add runc}}
 
== Configuration ==
 
=== Set up a minimal container ===
 
Here are the steps to create a minimal container using runc and Alpine Linux in {{Path|/opt/busybox-container}}. Adjust the path in the following commands, if required.


{{Cmd|# apk add runc}}
{{Cmd|# mkdir /opt/busybox-container}}
{{Cmd|# mkdir /opt/busybox-container}}
{{Cmd|# apk --arch x86_64 -X https://dl-cdn.alpinelinux.org/alpine/edge/main/ --root /opt/busybox-container/rootfs --initdb --no-cache --allow-untrusted add busybox}}
 
The creation of the root filesystem and the generation of the spec file is creating what is known as an OCI bundle. By using the Alpine Package Keeper (APK), we can create a bundle from pre-built software available for Alpine.
 
{{Cmd|# apk --arch x86_64 -X <nowiki>https://dl-cdn.alpinelinux.org/alpine/edge/main/</nowiki> --root /opt/busybox-container/rootfs --initdb --no-cache --allow-untrusted add busybox}}
 
{{Cmd|# cd /opt/busybox-container && runc spec}}
{{Cmd|# cd /opt/busybox-container && runc spec}}
{{Cmd|# cd /opt/busybox-container}}
 
Running the above command generates a configuration file {{Path|config.json}} which follows the [https://github.com/opencontainers/runtime-spec/blob/main/spec.md OCI Runtime Specification]. This configuration file can be modified to set-up mounts within the container amongst other settings.
 
{{Cmd|# runc run busybox-1}}
{{Cmd|# runc run busybox-1}}
== Crun ==
[https://github.com/containers/crun Crun] is a fast and lightweight fully featured OCI runtime and C library for running containers. The {{Pkg|crun}} package is an alternative to {{Pkg|runc}} package and it can be installed with {{Cmd|# apk add crun}}
All the commands in the examples given above can be switched to use {{ic|crun}} instead of {{ic|runc}}.
When replacing {{ic|runc}} by {{ic|crun}} recreate your containers. Even though, {{Pkg|crun}} replaces {{Pkg|runc}} the containers made with the latter are unusable until recreated.
== Troubleshooting ==
== See also ==
* [https://github.com/opencontainers/runc/tree/main?tab=readme-ov-file#using-runc Official User Guide for Runc]
* [https://www.redhat.com/en/blog/introduction-crun An introduction to crun]
[[Category:Virtualization]]

Latest revision as of 05:16, 23 September 2025

runc is a CLI tool for spawning and running containers on Linux according to the OCI specification, implemented in Go. This page provides instructions to setup containers using runc.

The tool is meant as a low-level tool and is intended to deal with the plumbing of container. The expectaiton is is it is used by higher level container software (such as Docker and Podman) to provide an interface better suited at common tasks. However, it can be useful for learning how things work, small tests or building your own tooling.

Prerequisites

Installation

Install the runc package:

# apk add runc

Configuration

Set up a minimal container

Here are the steps to create a minimal container using runc and Alpine Linux in /opt/busybox-container. Adjust the path in the following commands, if required.

# mkdir /opt/busybox-container

The creation of the root filesystem and the generation of the spec file is creating what is known as an OCI bundle. By using the Alpine Package Keeper (APK), we can create a bundle from pre-built software available for Alpine.

# apk --arch x86_64 -X https://dl-cdn.alpinelinux.org/alpine/edge/main/ --root /opt/busybox-container/rootfs --initdb --no-cache --allow-untrusted add busybox

# cd /opt/busybox-container && runc spec

Running the above command generates a configuration file config.json which follows the OCI Runtime Specification. This configuration file can be modified to set-up mounts within the container amongst other settings.

# runc run busybox-1

Crun

Crun is a fast and lightweight fully featured OCI runtime and C library for running containers. The crun package is an alternative to runc package and it can be installed with

# apk add crun

All the commands in the examples given above can be switched to use crun instead of runc.

When replacing runc by crun recreate your containers. Even though, crun replaces runc the containers made with the latter are unusable until recreated.

Troubleshooting

See also