diff --git a/backend/app/dto/docker.go b/backend/app/dto/docker.go index 4ee193d78..240794d9e 100644 --- a/backend/app/dto/docker.go +++ b/backend/app/dto/docker.go @@ -5,6 +5,7 @@ type DaemonJsonUpdateByFile struct { } type DaemonJsonConf struct { + IsSwarm bool `json:"isSwarm"` Status string `json:"status"` Version string `json:"version"` Mirrors []string `json:"registryMirrors"` diff --git a/backend/app/service/docker.go b/backend/app/service/docker.go index cc51271f9..55efbffa5 100644 --- a/backend/app/service/docker.go +++ b/backend/app/service/docker.go @@ -49,59 +49,60 @@ func (u *DockerService) LoadDockerStatus() string { } func (u *DockerService) LoadDockerConf() *dto.DaemonJsonConf { - status := constant.StatusRunning + var data dto.DaemonJsonConf + data.IPTables = true + data.Status = constant.StatusRunning stdout, err := cmd.Exec("systemctl is-active docker") if string(stdout) != "active\n" || err != nil { - status = constant.Stopped + data.Status = constant.Stopped } - version := "-" + data.IsSwarm = false + stdout2, _ := cmd.Exec("docker info | grep Swarm") + if string(stdout2) == " Swarm: active\n" { + data.IsSwarm = true + } + data.Version = "-" client, err := docker.NewDockerClient() if err == nil { ctx := context.Background() itemVersion, err := client.ServerVersion(ctx) if err == nil { - version = itemVersion.Version + data.Version = itemVersion.Version } } if _, err := os.Stat(constant.DaemonJsonPath); err != nil { - return &dto.DaemonJsonConf{Status: status, IPTables: true, Version: version} + return &data } file, err := os.ReadFile(constant.DaemonJsonPath) if err != nil { - return &dto.DaemonJsonConf{Status: status, IPTables: true, Version: version} + return &data } var conf daemonJsonItem deamonMap := make(map[string]interface{}) if err := json.Unmarshal(file, &deamonMap); err != nil { - return &dto.DaemonJsonConf{Status: status, IPTables: true, Version: version} + return &data } arr, err := json.Marshal(deamonMap) if err != nil { - return &dto.DaemonJsonConf{Status: status, IPTables: true, Version: version} + return &data } if err := json.Unmarshal(arr, &conf); err != nil { - return &dto.DaemonJsonConf{Status: status, IPTables: true, Version: version} + return &data } if _, ok := deamonMap["iptables"]; !ok { conf.IPTables = true } - driver := "cgroupfs" + data.CgroupDriver = "cgroupfs" for _, opt := range conf.ExecOpts { if strings.HasPrefix(opt, "native.cgroupdriver=") { - driver = strings.ReplaceAll(opt, "native.cgroupdriver=", "") + data.CgroupDriver = strings.ReplaceAll(opt, "native.cgroupdriver=", "") break } } - data := dto.DaemonJsonConf{ - Status: status, - Version: version, - Mirrors: conf.Mirrors, - Registries: conf.Registries, - IPTables: conf.IPTables, - LiveRestore: conf.LiveRestore, - CgroupDriver: driver, - } - + data.Mirrors = conf.Mirrors + data.Registries = conf.Registries + data.IPTables = conf.IPTables + data.LiveRestore = conf.LiveRestore return &data } diff --git a/frontend/src/api/interface/container.ts b/frontend/src/api/interface/container.ts index 66b4acc1a..3ae71ec3d 100644 --- a/frontend/src/api/interface/container.ts +++ b/frontend/src/api/interface/container.ts @@ -247,6 +247,7 @@ export namespace Container { operation: string; } export interface DaemonJsonConf { + isSwarm: boolean; status: string; version: string; registryMirrors: Array; diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index ee3329c43..7e12c906e 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -557,7 +557,9 @@ const message = { mirrorsHelper: 'If empty, mirror acceleration is disabled. The accelerated URL is used first for the operation, and will skipped when the request times out', registries: 'Insecure registries', - liveHelper: 'Whether to close all containers when stopping the docker service', + liveHelper: + 'Allows the running container state to be preserved in case of unexpected shutdown or crash of the Docker daemon', + liveWithSwarmHelper: 'live-restore daemon configuration is incompatible with swarm mode.', daemonJsonPath: 'Conf Path', serviceUnavailable: 'Docker service is not started at present, please click', startIn: ' to start', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index 5901894d7..87e4a814b 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -564,7 +564,8 @@ const message = { mirrors: '镜像加速', mirrorsHelper: '为空则关闭镜像加速;优先使用加速 URL 执行操作,请求超时将跳过使用默认加速方式', registries: '私有仓库', - liveHelper: '停止 docker 服务时,是否关闭所有容器', + liveHelper: '允许在 Docker 守护进程发生意外停机或崩溃时保留正在运行的容器状态', + liveWithSwarmHelper: 'live-restore 守护进程配置与 Swarm 模式不兼容', daemonJsonPath: '配置路径', serviceUnavailable: '当前未启动 Docker 服务,请在', startIn: '中开启', diff --git a/frontend/src/views/container/setting/index.vue b/frontend/src/views/container/setting/index.vue index cc539dfa3..ed284b8f7 100644 --- a/frontend/src/views/container/setting/index.vue +++ b/frontend/src/views/container/setting/index.vue @@ -66,8 +66,11 @@ - + {{ $t('container.liveHelper') }} + + {{ $t('container.liveWithSwarmHelper') }} + @@ -151,6 +154,7 @@ const extensions = [javascript(), oneDark]; const confShowType = ref('base'); const form = reactive({ + isSwarm: false, status: '', version: '', mirrors: '', @@ -250,6 +254,7 @@ const onSubmitSave = async () => { let itemMirrors = form.mirrors.split('\n'); let itemRegistries = form.registries.split('\n'); let param = { + isSwarm: form.isSwarm, status: form.status, version: '', registryMirrors: itemMirrors.filter(function (el) { @@ -294,6 +299,7 @@ const changeMode = async () => { const search = async () => { const res = await loadDaemonJson(); + form.isSwarm = res.data.isSwarm; form.status = res.data.status; form.version = res.data.version; form.cgroupDriver = res.data.cgroupDriver;