diff --git a/backend/app/service/docker.go b/backend/app/service/docker.go index af9137db3..29b9d5450 100644 --- a/backend/app/service/docker.go +++ b/backend/app/service/docker.go @@ -2,6 +2,7 @@ package service import ( "bufio" + "context" "encoding/json" "io/ioutil" "os" @@ -39,7 +40,12 @@ type daemonJsonItem struct { func (u *DockerService) LoadDockerStatus() string { status := constant.StatusRunning - if _, err := docker.NewDockerClient(); err != nil { + cli, err := docker.NewDockerClient() + if err != nil { + status = constant.Stopped + } + pong, err := cli.Ping(context.Background()) + if !pong.Experimental || err != nil { status = constant.Stopped } return status diff --git a/backend/app/service/image_repo.go b/backend/app/service/image_repo.go index a4bbfe181..8d1091570 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" "os/exec" "github.com/1Panel-dev/1Panel/backend/app/dto" @@ -56,8 +57,24 @@ func (u *ImageRepoService) Create(imageRepoDto dto.ImageRepoCreate) error { if imageRepo.ID != 0 { return constant.ErrRecordExist } + + fileSetting, err := settingRepo.Get(settingRepo.WithByKey("DaemonJsonPath")) + if err != nil { + return err + } + if len(fileSetting.Value) == 0 { + return errors.New("error daemon.json path in request") + } + if _, err := os.Stat(fileSetting.Value); err != nil && os.IsNotExist(err) { + if err = os.MkdirAll(fileSetting.Value, os.ModePerm); err != nil { + if err != nil { + return err + } + } + } + if imageRepoDto.Protocol == "http" { - file, err := ioutil.ReadFile(constant.DaemonJsonDir) + file, err := ioutil.ReadFile(fileSetting.Value) if err != nil { return err } @@ -76,7 +93,7 @@ func (u *ImageRepoService) Create(imageRepoDto dto.ImageRepoCreate) error { if err != nil { return err } - if err := ioutil.WriteFile(constant.DaemonJsonDir, newJson, 0640); err != nil { + if err := ioutil.WriteFile(fileSetting.Value, newJson, 0640); err != nil { return err } } diff --git a/backend/constant/container.go b/backend/constant/container.go index 8ecb8c10a..82873a963 100644 --- a/backend/constant/container.go +++ b/backend/constant/container.go @@ -14,7 +14,6 @@ const ( ComposeOpRestart = "restart" ComposeOpRemove = "remove" - DaemonJsonDir = "/opt/1Panel/docker/conf/daemon.json" TmpDockerBuildDir = "/opt/1Panel/data/docker/build" TmpComposeBuildDir = "/opt/1Panel/data/docker/compose" ) diff --git a/frontend/src/api/modules/container.ts b/frontend/src/api/modules/container.ts index 8e3e37171..78e6ba22c 100644 --- a/frontend/src/api/modules/container.ts +++ b/frontend/src/api/modules/container.ts @@ -130,6 +130,9 @@ export const dockerOperate = (params: Container.DockerOperate) => { export const loadDaemonJson = () => { return http.get(`/containers/daemonjson`); }; +export const loadDockerStatus = () => { + return http.get(`/containers/docker/status`); +}; export const updateDaemonJson = (params: Container.DaemonJsonConf) => { return http.post(`/containers/daemonjson/update`, params); }; diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index e1edec29c..eecd9c9bc 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -459,6 +459,8 @@ export default { registries: 'Insecure registries', liveHelper: 'Whether to close all containers when stopping the docker service', daemonJsonPath: 'Conf Path', + serviceUnavailable: 'Docker service is not started at present, please click', + startIn: ' to start', }, cronjob: { cronTask: 'Task', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index ecdebde3e..65e1402e2 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -466,6 +466,8 @@ export default { registries: '私有仓库', liveHelper: '停止 docker 服务时,是否关闭所有容器', daemonJsonPath: '配置路径', + serviceUnavailable: '当前未启动 Docker 服务,请在', + startIn: '中开启', }, cronjob: { cronTask: '计划任务', diff --git a/frontend/src/views/container/compose/index.vue b/frontend/src/views/container/compose/index.vue index 2e975e718..e9f4790e4 100644 --- a/frontend/src/views/container/compose/index.vue +++ b/frontend/src/views/container/compose/index.vue @@ -1,7 +1,14 @@