Skip to content

Commit

Permalink
fix: 容器配置文件为空时,删除配置文件 (#553)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssongliu authored Apr 9, 2023
1 parent 295f2a5 commit 241a4e6
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions backend/app/service/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ func (u *DockerService) UpdateConf(req dto.DaemonJsonConf) error {
deamonMap["exec-opts"] = []string{"native.cgroupdriver=systemd"}
}
}
if len(deamonMap) == 0 {
_ = os.Remove(constant.DaemonJsonPath)
return nil
}
newJson, err := json.MarshalIndent(deamonMap, "", "\t")
if err != nil {
return err
Expand All @@ -172,6 +176,10 @@ func (u *DockerService) UpdateConf(req dto.DaemonJsonConf) error {
}

func (u *DockerService) UpdateConfByFile(req dto.DaemonJsonUpdateByFile) error {
if len(req.File) == 0 {
_ = os.Remove(constant.DaemonJsonPath)
return nil
}
if _, err := os.Stat(constant.DaemonJsonPath); err != nil && os.IsNotExist(err) {
if err = os.MkdirAll(path.Dir(constant.DaemonJsonPath), os.ModePerm); err != nil {
return err
Expand Down

0 comments on commit 241a4e6

Please sign in to comment.