Jq修改docker-daemon.json开启关闭live-restore
来自三线的随记
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