Docker 关机自动关闭
如果Docker的数据在ZFS中,最好就在关机前自动关闭Docker容器,否则重启后由于ZFS还没挂载容易导致脏数据
创建一个Service:
[Unit]
Description=auto shutdown all docker containers
DefaultDependencies=no
Before=shutdown.target reboot.target halt.target
After=docker.service
Requires=docker.service
[Service]
Type=oneshot
RemainAfterExit=yes
WorkingDirectory=/home/evalexp/service/app
ExecStart=/bin/true
ExecStop=/usr/bin/docker compose down
TimeoutStopSec=180
[Install]
WantedBy=multi-user.target
这样在系统退出时,就会先主动关闭Docker容器。
配置Docker走代理
加速连接很垃圾,不如直接配置代理
修改文件/etc/systemd/system/multi-user.target.wants/docker.service
:
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service containerd.service
Wants=network-online.target
Requires=docker.socket
Wants=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
Environment=HTTP_PROXY=http://100.98.212.46:7890
Environment=HTTPS_PROXY=http://100.98.212.46:7890
# 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
添加上面的Environment
字段即可。