From b5f94b2f037fc887b432b5a61047272a1b5e7dc0 Mon Sep 17 00:00:00 2001 From: ssongliu Date: Fri, 2 Dec 2022 14:10:01 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20daemon.json=20=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E7=A7=BB=E9=99=A4=E7=A9=BA=E5=80=BC=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/service/docker.go | 24 ++++++++++++++++++++---- backend/app/service/image_repo.go | 8 +++++++- backend/constant/container.go | 2 +- frontend/src/lang/modules/en.ts | 4 ++-- frontend/src/lang/modules/zh.ts | 4 ++-- 5 files changed, 32 insertions(+), 10 deletions(-) diff --git a/backend/app/service/docker.go b/backend/app/service/docker.go index d8ceec8a1..9458ffa31 100644 --- a/backend/app/service/docker.go +++ b/backend/app/service/docker.go @@ -79,10 +79,26 @@ func (u *DockerService) UpdateConf(req dto.DaemonJsonConf) error { if err := json.Unmarshal(file, &deamonMap); err != nil { return err } - deamonMap["registry-mirrors"] = req.Mirrors - deamonMap["insecure-registries"] = req.Registries - deamonMap["bip"] = req.Bip - deamonMap["live-restore"] = req.LiveRestore + if len(req.Registries) == 0 { + delete(deamonMap, "insecure-registries") + } else { + deamonMap["insecure-registries"] = req.Registries + } + if len(req.Mirrors) == 0 { + delete(deamonMap, "insecure-mirrors") + } else { + deamonMap["insecure-mirrors"] = req.Mirrors + } + if len(req.Bip) == 0 { + delete(deamonMap, "bip") + } else { + deamonMap["bip"] = req.Bip + } + if !req.LiveRestore { + delete(deamonMap, "live-restore") + } else { + deamonMap["live-restore"] = req.LiveRestore + } if opts, ok := deamonMap["exec-opts"]; ok { if optsValue, isArray := opts.([]interface{}); isArray { for i := 0; i < len(optsValue); i++ { diff --git a/backend/app/service/image_repo.go b/backend/app/service/image_repo.go index b991b6cdf..a4bbfe181 100644 --- a/backend/app/service/image_repo.go +++ b/backend/app/service/image_repo.go @@ -3,6 +3,7 @@ package service import ( "encoding/json" "io/ioutil" + "os/exec" "github.com/1Panel-dev/1Panel/backend/app/dto" "github.com/1Panel-dev/1Panel/backend/constant" @@ -55,7 +56,7 @@ func (u *ImageRepoService) Create(imageRepoDto dto.ImageRepoCreate) error { if imageRepo.ID != 0 { return constant.ErrRecordExist } - if imageRepo.Protocol == "http" { + if imageRepoDto.Protocol == "http" { file, err := ioutil.ReadFile(constant.DaemonJsonDir) if err != nil { return err @@ -85,6 +86,11 @@ func (u *ImageRepoService) Create(imageRepoDto dto.ImageRepoCreate) error { if err := imageRepoRepo.Create(&imageRepo); err != nil { return err } + cmd := exec.Command("systemctl", "restart", "docker") + stdout, err := cmd.CombinedOutput() + if err != nil { + return errors.New(string(stdout)) + } return nil } diff --git a/backend/constant/container.go b/backend/constant/container.go index 6b74d4db0..8ecb8c10a 100644 --- a/backend/constant/container.go +++ b/backend/constant/container.go @@ -14,7 +14,7 @@ const ( ComposeOpRestart = "restart" ComposeOpRemove = "remove" - DaemonJsonDir = "/opt/1Panel/docker/config/daemon.json" + DaemonJsonDir = "/opt/1Panel/docker/conf/daemon.json" TmpDockerBuildDir = "/opt/1Panel/data/docker/build" TmpComposeBuildDir = "/opt/1Panel/data/docker/compose" ) diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index c24e4f2be..330d06f55 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -349,7 +349,7 @@ export default { containerPort: 'Container port', serverPort: 'Host port', cmd: 'Command', - cmdHelper: 'one in a row, for example, echo "hello"', + cmdHelper: 'one in a row, for example: \n/bin/bash \necho "hello"', autoRemove: 'Auto remove', cpuQuota: 'NacosCPU', memoryLimit: 'Memory', @@ -386,7 +386,7 @@ export default { size: 'Size', from: 'From', tag: 'Tag', - tagHelper: 'one in a row, for example, key=value', + tagHelper: 'one in a row, for example, \nkey1=value1\nkey2=value2', imageNameHelper: 'Image name and Tag, for example: nginx:latest', network: 'Network', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index 3acc61939..871c5510c 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -354,7 +354,7 @@ export default { containerPort: '容器端口', serverPort: '服务器端口', cmd: '启动命令', - cmdHelper: '一行一个,例: echo "hello"', + cmdHelper: '一行一个,例:\n/bin/bash \necho "hello"', autoRemove: '容器退出后自动删除容器', cpuQuota: 'CPU 限制', memoryLimit: '内存限制', @@ -398,7 +398,7 @@ export default { size: '大小', from: '来源', tag: '标签', - tagHelper: '一行一个,例: key=value', + tagHelper: '一行一个,例: \nkey1=value1\nkey2=value2', imageNameHelper: '镜像名称及 Tag,例:nginx:latest', network: '网络',