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/ lib
cp /lib/ lib
cp /lib/ lib
cp /lib/ lib
sudo systemd-nspawn --machine mycontainer --directory $PWD /lib/ /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/ --list /usr/bin/go (0x00007fffb84c6000) => /lib/ (0x00007f99059bd000) => /lib/ (0x00007f9905618000)
/lib64/ => /lib/ (0x0000563342c82000)

Then to run "go" you just need and

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

Postar um comentário

Postagens mais visitadas