Hello World web app with runc

runc is a lightweight universal runtime container. runc is a CLI tool for spawning and running containers according to the OCP specification. Containers are started as a child process of runC and can be embedded into various other systems without having to run a Docker daemon.

Assuming you have installed the runc cli. Here is how I built a simple hello-world container serving a static site with nginx using docker export.

Create the App

$ cd /tmp
$ mkdir -p /tmp/hello-runc
$ cat > /tmp/hello-runc/index.html
<html><body>Hello runc...</body></html>  

Build the Docker container

$ cat > /tmp/Dockerfile
FROM aminjam/nginx-static  
RUN apt-get install -y curl  
ADD ./hello-runc /home/app  
$ docker build -t nginx-app .

Creater and Export Docker container

$ docker export $(docker create nginx-app) > myapp.tar

Create rootfs

$ mkdir -p /tmp/rootfs
$ tar -C /tmp/rootfs -xf myapp.tar
$ sudo chown -R root:root /tmp/rootfs #files should be owned by the container user (root)

Start runc container

$ cd rootfs && runc spec > ../config.json && cd ..
$ cat config.json | grep readonly
# By default this flag is set to true, but make sure readonly flag is set to false. This is primary for nginx logs and temp files
$ sudo runc 

Start the app

$ cd home/app
$ nginx &
<CTRL-C>  
$ ps #make sure nginx is running
$ curl -i http://127.0.0.1

You should be able to see the response from index.html. This is a POC runC container that I wanted to play around and take note of for future reference. I hope that helps if you are looking to play around with runc.

comments powered by Disqus