From 9a3ac36236bb8cde3a602bc05dff7f9af5cb5d90 Mon Sep 17 00:00:00 2001 From: Justin Cormack Date: Wed, 7 Jun 2017 16:04:09 +0100 Subject: [PATCH] Add an example of building an application and running in Docker or LinuxKit Signed-off-by: Justin Cormack --- examples/README.md | 23 +++++++++++++++++++++++ examples/docker.yml | 9 +++++++++ examples/linuxkit.yml | 18 ++++++++++++++++++ examples/nginx.yml | 12 ++++++++++++ 4 files changed, 62 insertions(+) create mode 100644 examples/README.md create mode 100644 examples/docker.yml create mode 100644 examples/linuxkit.yml create mode 100644 examples/nginx.yml diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 000000000..d7463c5d0 --- /dev/null +++ b/examples/README.md @@ -0,0 +1,23 @@ +Examples of building an image to run on LinuxKit or on a host + +Currently the `moby` tool can output formats suitable for LinuxKit to boot on +a VM, and also some formats for running natively. + +The `docker` format adds a `Dockerfile` to the tarball and expects a similar +file structure to `LinuxKit` but with the low level system setup pieces removed +as this will already be set up in a container. + +The `mobytest/init-container` image in this repository has an example setup that +initialises `containerd` in exactly the same way as it runs in LinuxKit, which will +then start the `onboot` and `service` containers. The example below shows how you +can run `nginx` on either of these base configs. + +``` +moby build -output docker -o - docker.yml nginx.yml | docker build -t dockertest - +docker run -d -p 80:80 --privileged dockertest + +moby build -output kernel+initrd linuxkit.yml nginx.yml +linuxkit run nginx +``` + +Both of these will run the same `nginx` either in a VM or a container. diff --git a/examples/docker.yml b/examples/docker.yml new file mode 100644 index 000000000..32186c048 --- /dev/null +++ b/examples/docker.yml @@ -0,0 +1,9 @@ +init: + - mobytest/init-container:b5de246b2790d74d53bae583a95c87869ca003e6 + - linuxkit/runc:3a4e6cbf15470f62501b019b55e1caac5ee7689f + - linuxkit/containerd:5749f2e9e65395cc6635229e8da0e0d484320ddf + - linuxkit/ca-certificates:75cf419fb58770884c3464eb687ec8dfc704169d +trust: + org: + - linuxkit + - mobytest diff --git a/examples/linuxkit.yml b/examples/linuxkit.yml new file mode 100644 index 000000000..80a462b72 --- /dev/null +++ b/examples/linuxkit.yml @@ -0,0 +1,18 @@ +kernel: + image: "linuxkit/kernel:4.9.x" + cmdline: "console=ttyS0" +init: + - linuxkit/init:1b8a7e394d2ec2f1fdb4d67645829d1b5bdca037 + - linuxkit/runc:3a4e6cbf15470f62501b019b55e1caac5ee7689f + - linuxkit/containerd:5749f2e9e65395cc6635229e8da0e0d484320ddf + - linuxkit/ca-certificates:75cf419fb58770884c3464eb687ec8dfc704169d +onboot: + - name: dhcpcd + image: "linuxkit/dhcpcd:7d2b8aaaf20c24ad7d11a5ea2ea5b4a80dc966f1" + command: ["/sbin/dhcpcd", "--nobackground", "-f", "/dhcpcd.conf", "-1"] +services: + - name: rngd + image: "linuxkit/rngd:1fa4de44c961bb5075647181891a3e7e7ba51c31" +trust: + org: + - linuxkit diff --git a/examples/nginx.yml b/examples/nginx.yml new file mode 100644 index 000000000..e5405c3cd --- /dev/null +++ b/examples/nginx.yml @@ -0,0 +1,12 @@ +services: + - name: nginx + image: "nginx:alpine" + capabilities: + - CAP_NET_BIND_SERVICE + - CAP_CHOWN + - CAP_SETUID + - CAP_SETGID + - CAP_DAC_OVERRIDE +trust: + org: + - library