/etc/systemd/system/docker-tcp.socket中的配置如下:
[Unit]
Description=Docker Socket for the API [Socket] ListenStream=x.x.x.x:2375 BindIPv6Only=both Service=docker.service [Install] WantedBy=sockets.target
每次重启后都要运行下面的命令才生效:
systemctl enable docker-tcp.socket systemctl stop docker systemctl start docker-tcp.socket systemctl start docker
请问如何解决这个问题?
参考 Starting Docker Daemon on Demand with Socket Activation ,在 [Unit] 中添加 PartOf=docker.service 解决了问题
PartOf 的作用(来源):
When systemd stops or restarts the units listed here, the action is propagated to this unit
[Unit] 节点下还有别的标签可以帮你“自动化”
Description:简短描述Documentation:文档地址Requires:当前 Unit 依赖的其他 Unit,如果它们没有运行,当前 Unit 会启动失败Wants:与当前 Unit 配合的其他 Unit,如果它们没有运行,当前 Unit 不会启动失败BindsTo:与Requires类似,它指定的 Unit 如果退出,会导致当前 Unit 停止运行Before:如果该字段指定的 Unit 也要启动,那么必须在当前 Unit 之后启动After:如果该字段指定的 Unit 也要启动,那么必须在当前 Unit 之前启动Conflicts:这里指定的 Unit 不能与当前 Unit 同时运行Condition...:当前 Unit 运行必须满足的条件,否则不会运行Assert...:当前 Unit 运行必须满足的条件,否则会报启动失败参考:
http://www.ruanyifeng.com/blog/2016/03/systemd-tutorial-commands.html
https://blogs.mercenaryunion.com/2017/10/28/linux/linux-service/