Docker service 啟動 關(guān)閉

1 、dockerd & 啟動docker 后如何停止。

  • 先找到dockerd 運行的pid
    cat /etc/run/docker.pid
    比如是pid是 123
    kill -9 123
    刪除文件
    rm /etc/run/docker.pid

2、設(shè)置開機自動啟動

  • 配置service
    vi /usr/lib/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/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=infinity
LimitNPROC=infinity
TimeoutStartSec=0
Delegate=yes
KillMode=process
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
 
[Install]
WantedBy=multi-user.target

  • systemctl daemon-reload
  • systemctl start docker.service
  • systemctl enable docker.service#自動啟動
    • 輸出如下
      Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service。
  • 檢驗
# ps aux|grep docker
root      2262  0.1  4.4 472948 44944 ?        Ssl  16:38   0:00 /usr/bin/dockerd
root      2266  0.2  1.3 277032 13540 ?        Ssl  16:38   0:01 docker-containerd --config /var/run/docker/containerd/containerd.toml
root      2895  0.0  0.0 112660   972 pts/0    S+   16:48   0:00 grep --color=auto docker

3 docker 容器自動重啟

docker update --restart=always xxx

no - 容器退出時,不重啟容器; on-failure - 只有在非0狀態(tài)退出時才從新啟動容器; always - 無論退出狀態(tài)是如何,都重啟容器;

  • 最多重啟10次
    sudo docker run --restart=on-failure:10 redis

4。防火墻

systemctl enable|disable firewalld #開機啟動
systemctl start|stop|restart firewalld #啟動、停止、重啟firewalld

5. enforce

臨時關(guān)閉:

[root@localhost ~] getenforce
Enforcing

[root@localhost ~] setenforce 0
[root@localhost ~] getenforce
Permissive

永久關(guān)閉:

[root@localhost ~] vim /etc/sysconfig/selinux

SELINUX=enforcing 改為 SELINUX=disabled

重啟服務(wù)reboot

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容