Skip to content

Instantly share code, notes, and snippets.

@joshwget
Last active August 22, 2016 20:45
Show Gist options
  • Save joshwget/05a6e6b7e76b00ffda645c7e224df04f to your computer and use it in GitHub Desktop.
Save joshwget/05a6e6b7e76b00ffda645c7e224df04f to your computer and use it in GitHub Desktop.

These instructions explain how to run runv-docker as a system service. The first step is to produce the necessary build artifacts for the system servivce.

We can perform this build process in a RancherOS Ubuntu console. First, switch to the Ubuntu console.

sudo ros console switch -f ubuntu

Install a few packages necessary for building.

sudo apt-get update
sudo apt-get install -y git cpio autoconf automake pkg-config make gcc golang qemu

Build runv.

sudo -s
export GOPATH=/usr/local/go
go get -d github.com/hyperhq/runv
cd $GOPATH/src/github.com/hyperhq/runv
./autogen.sh
./configure --without-xen
make install

Build runv kernel and image.

sudo -s
cd /opt
git clone https://github.com/hyperhq/hyperstart
cd hyperstart
./autogen.sh
./configure
make

From this build process, four assets are produced:

  • runv (/usr/bin/runv)
  • runv-containerd (/usr/bin/runv)
  • kernel (/opt/hyperstart/build/kernel)
  • hyper-initrd.img /opt/hyperstart/build/hyper-initrd.img)

Copy these four assets along with the following Dockerfile into a new directory. The following Dockerfile assumes that these assets are in the current directory.

FROM ubuntu:16.04
RUN apt-get update && apt-get install -y qemu iptables kmod iproute2
COPY runv runv-containerd /usr/bin/
RUN mkdir assets
COPY kernel hyper-initrd.img /assets/
RUN mkdir -p /run/runv-containerd
COPY runv-docker.sh /
CMD /runv-docker.sh

The runv-docker.sh script is as follows:

#!/bin/bash
runv-containerd --debug --driver qemu --kernel /assets/kernel --initrd /assets/hyper-initrd.img &
docker.dist daemon -D -l debug --containerd=/run/runv-containerd/containerd.sock -H unix:///var/run/runv-docker/docker.sock -p /var/run/runv-docker.pid -g /var/lib/runv-docker --exec-root=/var/run/runv-docker >>/var/log/runv-docker.log 2>&1

Build the image with docker build -t <image> ..

Now a system service can be defined using the image from the previous step.

runv-docker:
  image: <image>
  labels:
    io.rancher.os.scope: system
    io.rancher.os.after: docker
  net: host
  uts: host
  pid: host
  ipc: host
  privileged: true
  restart: always
  volumes_from:
  - system-volumes
  - command-volumes
  - user-volumes
  volumes:
  - /var/lib/runv-docker:/var/lib/runv-docker
  - /var/run/runv-docker:/var/run/runv-docker

If this service config is hosted at a given URL, it can be enabled after boot with the following commands:

ros service enable <URL>
ros service up -d runv-docker

The service can also be enabled by adding it to your cloud-config:

#cloud-config
rancher:
  services_include:
    <URL>: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment