Linux service에 docker 등록

Sbae·2024년 6월 26일
0
post-thumbnail

Docker를 binary로?

Docker를 binary로 설치했어요.
docker가 system daemon으로 작동하는데
나는 sudo systemctl status docker를 치면 아래 화면처럼 나오게 하고싶어요.

systemctl status docker

1번 방법

  1. sudo vi /etc/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target

[Service]
Type=notify
ExecStart=/usr/local/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always

StartLimitBurst=3
StartLimitInterval=60s

[Install]
WantedBy=multi-user.target
  1. 기존 실행되는 daemon 종료 후 재 실행
sudo kill $(cat /var/run/docker.pid)
sudo rm /var/run/docker.pid

sudo systemctl daemon-reload
sudo systemctl restart docker
sudo systemctl status docker
  1. sudo systemctl status docker

2번 방법

  1. sudo vi /etc/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target docker.socket firewalld.service containerd.service time-set.target
Wants=network-online.target containerd.service
Requires=docker.socket

[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
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutStartSec=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
  1. sudo vi /etc/systemd/system/docker.socket
[Unit]
Description=Docker Socket for the API

[Socket]
# If /var/run is not implemented as a symlink to /run, you may need to
# specify ListenStream=/var/run/docker.sock instead.
ListenStream=/var/run/docker.sock
SocketMode=0660
SocketUser=root
SocketGroup=docker

[Install]
WantedBy=sockets.target
  1. 위와 동일
sudo kill $(cat /var/run/docker.pid)
sudo rm /var/run/docker.pid

sudo systemctl daemon-reload
sudo systemctl restart docker
sudo systemctl status docker

차이점을 아시나요?......

나도 알고싶다... 진짜 모르겠는데... 회사사람한테 물어봐도 전혀 아는사람이 없는데 혹시 아시는 분은 댓글이라도 남겨주세요 제발

참고 사이트

profile
끄적이는 일반인

0개의 댓글