mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-31 14:08:06 +08:00
fix: daemon.json 配置移除空值项
This commit is contained in:
parent
614570a4c7
commit
b5f94b2f03
@ -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++ {
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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"
|
||||
)
|
||||
|
@ -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',
|
||||
|
@ -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: '网络',
|
||||
|
Loading…
x
Reference in New Issue
Block a user