Docker ve systemd, containerd Üzerine Bazı Notlar

Ümit Kabuli
2 min readDec 31, 2022

Systemd sistem yöneticisi kullanan bir işletim sistemine yüklenen Docker systemd’ye özgü bir takım unit dosyalarını da sisteme yükler.

sudo systemctl start docker

Yukarıdaki komut

sudo systemctl start docker.service

komutuyla eşdeğerdir. Çünkü systemd’nin kurulum ayarlarına göre bir ünit dosyasının adı belirtilmiyorsa varsayılan olarak “.service”dir. Ünit dosyaları systemd’nin servisleri yönetirken, bir servisin diğerini ön gerektirmesi , hata yeniden yükleme kurallarının deklare edilmesi kontrol için geliştirdiği düz metin dosyalarıdır. “.service”, ”.mount”, “.socket” , “.target” gibi işlevlerine göre farklı uzantılara sagip olabilir. Benim docker’ı kurduğum Ubuntu 22.04 LTS’de docker.service dosyası “/lib/systemd/system” dizininde bulunuyor. Bir ünit dosyasının neye beezediğinin görülmesi için bir defaya mahsus tüm dosyayı aktaracağım:

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target docker.socket firewalld.service containerd.service
Wants=network-online.target
Requires=docker.socket containerd.service

[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd -H fd:// — containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always

# Note that StartLimit* options were moved from “Service” to “Unit” in systemd 229.
# Both the old, and new location are accepted by systemd 229 and up, so using the old location
# to make them work for either version of systemd.
StartLimitBurst=3

# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
# this option work for either version of systemd.
StartLimitInterval=60s

# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity

# Comment TasksMax if your systemd version does not support it.
# Only systemd 226 and above support this option.
TasksMax=infinity

# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes

# kill only the docker process, not all processes in the cgroup
KillMode=process
OOMScoreAdjust=-500

[Install]
WantedBy=multi-user.target

Dosyanın [Unit] bölümünden anlaşılacağı üzere docker.service işlenmesine devam etme docker.socket, containerd.socket ve başka bazı ünit dosyalarının ve onlara bağlı seervislerin çalıştırılmış olması gerekiyor.

ExecStart=/usr/bin/dockerd -H fd://containerd=/run/containerd/containerd.sock

satırı servisi başlatan satırdır. container.service dosyasındaki

ExecStart=/usr/bin/containerd

satırı ile containerd daemon’u öncelikle çalıştırılır. Çünkü docker’a göre containerd daha alt seviyedir, yani makineye daha yakın olan bir katmanda bulunur.

containerd.io site’sinde bulunan mimari yapıyı gösteren info-grafiği çok açıklayıcı buldum. Teknik ayrıntılara girmeden önce mimari tasarım mantığını kavramak önemlidir. Yoksa hangi komutu yazınca ne oluyor, bu teknikerliktir. Ağaçlara dikkat ederken, ormanı gözden kaçırmamak önemli…

$ containerd — help

Büyük kısmı C dilini andıran Go ile kodlanmış olan containerd’yi repodan indirip derleyip kurmak ve çeşitli debug modlarında çalıştırmak da mümkün. Dili fazla bilmeseniz de bug’ların yakalanmasına yardımcı olmuş olursunuz. Konuyu daha derinlemesine öğrenmeniz katkısı olur. Uğraşanlara kolaylıklar dilerim.

--

--