Jq修改docker-daemon.json开启关闭live-restore:修订间差异

来自三线的随记
无编辑摘要
无编辑摘要
 
(未显示同一用户的5个中间版本)
第1行: 第1行:
use jq tool to enable or disable docker live-restore feature
use jq tool to enable or disable docker live-restore feature / aka: use jq tool to edit json file


<br />
<br />


===enable===
===enable===
  jq '. + {"live-restore": true}' /etc/docker/daemon.json
 
==== modify the config file ====
  cat <<< $( jq '. + {"live-restore": true}' /etc/docker/daemon.json ) > /etc/docker/daemon.json
# Format file (If required)
jq <<< $(cat /etc/docker/daemon.json ) > /etc/docker/daemon.json
or in one command line:
jq '. + {"live-restore": true}' <<< $(cat /etc/docker/daemon.json ) > /etc/docker/daemon.json
or in one command line:
jq '. + {"live-restore": true}' /etc/docker/daemon.json | awk '{print > "/etc/docker/daemon.json"}'
tee 也可以实现一条命令结合jq改写json文件,懒得拼装了..<br />
 
==== modify and enable the live restore feature ====
jq '. + {"live-restore": true}' <<< $(cat /etc/docker/daemon.json ) > /etc/docker/daemon.json
  systemctl reload docker
  systemctl reload docker
  docker info | grep -i live
  docker info | grep -i liv<br />
<br />


===disable===
===disable===
  jq '. + {"live-restore": false}' /etc/docker/daemon.json
  jq '. + {"live-restore": false}' <<< $(cat /etc/docker/daemon.json ) > /etc/docker/daemon.json
  kill -SIGHUP $(pidof dockerd)
  kill -SIGHUP $(pidof dockerd)
  docker info | grep Live
  docker info | grep Live
<br />
<br />


=== more examples ===
===Other matters requiring attention===
对于挂载了/var/run/docker.sock的容器,需要手动重启 (挂载的是目录的话不会有这个问题)
 
docker挂载文件的机制是绑定主机上该文件的 inode。
 
当docker-engine热重启,docker.sock文件的inode值会改变,所以挂载会失效
 
====Workaround====
查看该主机上直接挂载 docker.sock 的容器   
docker inspect $(docker ps -q)|grep 'Source.*docker.sock\|Name": "/'|grep sock -B1|grep Name
重启之
 
<br />
 
===more examples===
https://gist.github.com/joar/776b7d176196592ed5d8
https://gist.github.com/joar/776b7d176196592ed5d8
<br />
[[分类:Linux]]
[[分类:Linux]]
[[分类:Docker]]
[[分类:Docker]]
{{DEFAULTSORT:jq}}
{{DEFAULTSORT:jq}}

2022年1月14日 (五) 16:11的最新版本

use jq tool to enable or disable docker live-restore feature / aka: use jq tool to edit json file


enable

modify the config file

cat <<< $( jq '. + {"live-restore": true}' /etc/docker/daemon.json ) > /etc/docker/daemon.json

# Format file (If required)
jq <<< $(cat /etc/docker/daemon.json ) > /etc/docker/daemon.json

or in one command line:

jq '. + {"live-restore": true}' <<< $(cat /etc/docker/daemon.json ) > /etc/docker/daemon.json

or in one command line:

jq '. + {"live-restore": true}' /etc/docker/daemon.json | awk '{print > "/etc/docker/daemon.json"}'

tee 也可以实现一条命令结合jq改写json文件,懒得拼装了..

modify and enable the live restore feature

jq '. + {"live-restore": true}' <<< $(cat /etc/docker/daemon.json ) > /etc/docker/daemon.json
systemctl reload docker
docker info | grep -i liv

disable

jq '. + {"live-restore": false}' <<< $(cat /etc/docker/daemon.json ) > /etc/docker/daemon.json
kill -SIGHUP $(pidof dockerd)
docker info | grep Live


Other matters requiring attention

对于挂载了/var/run/docker.sock的容器,需要手动重启 (挂载的是目录的话不会有这个问题)

docker挂载文件的机制是绑定主机上该文件的 inode。

当docker-engine热重启,docker.sock文件的inode值会改变,所以挂载会失效

Workaround

查看该主机上直接挂载 docker.sock 的容器   

docker inspect $(docker ps -q)|grep 'Source.*docker.sock\|Name": "/'|grep sock -B1|grep Name

重启之


more examples

https://gist.github.com/joar/776b7d176196592ed5d8