Running a smallest container using systemd

To run containers, you don't need docker. You just need linux kernel, and some tools to control kernel resources. Docker is a nice way to use container, but not the only one.

SystemD does the job. So if you have it will can run containers without docker as requirement. Since today systemd is the most used init system in linux world, it is a relevant fact.

In this post I will show you how to create a systemd container from scratch.

First all you need a empty directory where you will create a root file strucutre to be used inside the container. In this example I will run bash.

mkdir lib
cp /bin/bash bin/
cp /lib/ld-2.25.90.so lib
cp /lib/lic.so.6 lib
cp /lib/lidl.so.2 lib
cp /lib/libncursesw.so.6 lib
sudo systemd-nspawn --machine mycontainer --directory $PWD /lib/ld-2.25.90.so /bin/bash

Of course you can do the same with other binaries too. Eg. If you want to know what dependencies does "go" have, just run:

/lib/ld-2.25.90.so --list /usr/bin/go
linux-vdso.so.1 (0x00007fffb84c6000)
libpthread.so.0 => /lib/libpthread.so.0 (0x00007f99059bd000)
libc.so.6 => /lib/libc.so.6 (0x00007f9905618000)
/lib64/ld-linux-x86-64.so.2 => /lib/ld-2.25.90.so (0x0000563342c82000)

Then to run "go" you just need ld-linux.so and libpthread.so

If you want to create a docker image, you can refer to:

http://glaudiston.blogspot.com.br/2015/06/how-to-make-very-very-small-docker.html

Postar um comentário

Postagens mais visitadas