diff --git a/backend/app/dto/setting.go b/backend/app/dto/setting.go index 290e461a9..13d6e81fe 100644 --- a/backend/app/dto/setting.go +++ b/backend/app/dto/setting.go @@ -3,10 +3,11 @@ package dto import "time" type SettingInfo struct { - UserName string `json:"userName"` - Email string `json:"email"` - SystemIP string `json:"systemIP"` - SystemVersion string `json:"systemVersion"` + UserName string `json:"userName"` + Email string `json:"email"` + SystemIP string `json:"systemIP"` + SystemVersion string `json:"systemVersion"` + DockerSockPath string `json:"dockerSockPath"` SessionTimeout string `json:"sessionTimeout"` LocalTime string `json:"localTime"` diff --git a/backend/init/migration/migrate.go b/backend/init/migration/migrate.go index 265509494..9a094d773 100644 --- a/backend/init/migration/migrate.go +++ b/backend/init/migration/migrate.go @@ -56,6 +56,7 @@ func Init() { migrations.UpdateAcmeAccount, migrations.UpdateWebsiteSSL, migrations.AddWebsiteCA, + migrations.AddDockerSockPath, }) if err := m.Migrate(); err != nil { global.LOG.Error(err) diff --git a/backend/init/migration/migrations/v_1_9.go b/backend/init/migration/migrations/v_1_9.go index b2af274f8..a065c31cf 100644 --- a/backend/init/migration/migrations/v_1_9.go +++ b/backend/init/migration/migrations/v_1_9.go @@ -35,3 +35,13 @@ var UpdateWebsiteSSL = &gormigrate.Migration{ return nil }, } + +var AddDockerSockPath = &gormigrate.Migration{ + ID: "20231128-add-docker-sock-path", + Migrate: func(tx *gorm.DB) error { + if err := tx.Create(&model.Setting{Key: "DockerSockPath", Value: "unix:///var/run/docker.sock"}).Error; err != nil { + return err + } + return nil + }, +} diff --git a/backend/server/server.go b/backend/server/server.go index 7d67b1575..0fa3451a8 100644 --- a/backend/server/server.go +++ b/backend/server/server.go @@ -32,9 +32,9 @@ import ( func Start() { viper.Init() log.Init() - app.Init() db.Init() migration.Init() + app.Init() validator.Init() gob.Register(psession.SessionUser{}) cache.Init() diff --git a/backend/utils/docker/docker.go b/backend/utils/docker/docker.go index 2bf73230c..c4532e43a 100644 --- a/backend/utils/docker/docker.go +++ b/backend/utils/docker/docker.go @@ -2,6 +2,8 @@ package docker import ( "context" + + "github.com/1Panel-dev/1Panel/backend/app/model" "github.com/1Panel-dev/1Panel/backend/global" "github.com/docker/docker/api/types" @@ -14,7 +16,12 @@ type Client struct { } func NewClient() (Client, error) { - cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation()) + var settingItem model.Setting + _ = global.DB.Where("key = ?", "DockerSockPath").First(&settingItem).Error + if len(settingItem.Value) == 0 { + settingItem.Value = "unix:///var/run/docker.sock" + } + cli, err := client.NewClientWithOpts(client.FromEnv, client.WithHost(settingItem.Value), client.WithAPIVersionNegotiation()) if err != nil { return Client{}, err } @@ -25,7 +32,12 @@ func NewClient() (Client, error) { } func NewDockerClient() (*client.Client, error) { - cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation()) + var settingItem model.Setting + _ = global.DB.Where("key = ?", "DockerSockPath").First(&settingItem).Error + if len(settingItem.Value) == 0 { + settingItem.Value = "unix:///var/run/docker.sock" + } + cli, err := client.NewClientWithOpts(client.FromEnv, client.WithHost(settingItem.Value), client.WithAPIVersionNegotiation()) if err != nil { return nil, err } diff --git a/cmd/server/docs/docs.go b/cmd/server/docs/docs.go index a4ade107c..e0bb76457 100644 --- a/cmd/server/docs/docs.go +++ b/cmd/server/docs/docs.go @@ -16709,6 +16709,9 @@ const docTemplate = `{ "dingVars": { "type": "string" }, + "dockerSockPath": { + "type": "string" + }, "email": { "type": "string" }, diff --git a/cmd/server/docs/swagger.json b/cmd/server/docs/swagger.json index f5cde54ad..0aa60ec20 100644 --- a/cmd/server/docs/swagger.json +++ b/cmd/server/docs/swagger.json @@ -16702,6 +16702,9 @@ "dingVars": { "type": "string" }, + "dockerSockPath": { + "type": "string" + }, "email": { "type": "string" }, diff --git a/cmd/server/docs/swagger.yaml b/cmd/server/docs/swagger.yaml index e520ec657..15142f829 100644 --- a/cmd/server/docs/swagger.yaml +++ b/cmd/server/docs/swagger.yaml @@ -2292,6 +2292,8 @@ definitions: type: string dingVars: type: string + dockerSockPath: + type: string email: type: string emailVars: diff --git a/frontend/src/api/interface/setting.ts b/frontend/src/api/interface/setting.ts index 3ec666ed7..d3800d9d3 100644 --- a/frontend/src/api/interface/setting.ts +++ b/frontend/src/api/interface/setting.ts @@ -7,6 +7,7 @@ export namespace Setting { email: string; systemIP: string; systemVersion: string; + dockerSockPath: string; sessionTimeout: number; localTime: string; diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index b518e6ad9..58360d751 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -744,6 +744,12 @@ const message = { daemonJsonPath: 'Conf Path', serviceUnavailable: 'Docker service is not started at present, please click', startIn: ' to start', + sockPath: 'Socket Path', + sockPathHelper: 'Communication channel between Docker Daemon and the client', + sockPathHelper1: 'Default value is unix:///var/run/docker-x.sock', + sockPathMsg: + 'Saving the Socket Path setting may result in Docker service being unavailable. Do you want to continue?', + sockPathErr: 'Please select or enter the correct Docker sock file path', }, cronjob: { create: 'Create Cronjob', diff --git a/frontend/src/lang/modules/tw.ts b/frontend/src/lang/modules/tw.ts index a86fb50e1..fe01ec378 100644 --- a/frontend/src/lang/modules/tw.ts +++ b/frontend/src/lang/modules/tw.ts @@ -715,6 +715,11 @@ const message = { daemonJsonPath: '配置路徑', serviceUnavailable: '當前未啟動 Docker 服務,請在', startIn: '中開啟', + sockPath: 'Socket 路徑', + sockPathHelper: 'Docker 守護進程(Docker Daemon)與客戶端之間的通信通道', + sockPathHelper1: '默認值為 unix:///var/run/docker-x.sock', + sockPathMsg: '保存設定 Socket 路徑可能導致 Docker 服務不可用,是否繼續?', + sockPathErr: '請選擇或輸入正確的 Docker sock 文件路徑', }, cronjob: { create: '創建計劃任務', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index 335ff60a7..84adc44b3 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -716,6 +716,11 @@ const message = { daemonJsonPath: '配置路径', serviceUnavailable: '当前未启动 Docker 服务,请在', startIn: '中开启', + sockPath: 'Socket 路径', + sockPathHelper: 'Docker 守护进程(Docker Daemon)与客户端之间的通信通道', + sockPathHelper1: '默认值为 unix:///var/run/docker-x.sock', + sockPathMsg: '保存设置 Socket 路径可能导致 Docker 服务不可用,是否继续?', + sockPathErr: '请选择或输入正确的 Docker sock 文件路径', }, cronjob: { create: '创建计划任务', diff --git a/frontend/src/views/container/setting/index.vue b/frontend/src/views/container/setting/index.vue index 037fc8b84..0505be7c4 100644 --- a/frontend/src/views/container/setting/index.vue +++ b/frontend/src/views/container/setting/index.vue @@ -150,6 +150,16 @@ systemd + + + + + {{ $t('commons.button.set') }} + + + + {{ $t('container.sockPathHelper') }} + @@ -220,6 +230,7 @@ + @@ -240,6 +251,7 @@ import Mirror from '@/views/container/setting/mirror/index.vue'; import Registry from '@/views/container/setting/registry/index.vue'; import LogOption from '@/views/container/setting/log/index.vue'; import Ipv6Option from '@/views/container/setting/ipv6/index.vue'; +import SockPath from '@/views/container/setting/sock-path/index.vue'; import ConfirmDialog from '@/components/confirm-dialog/index.vue'; import i18n from '@/lang'; import { @@ -249,6 +261,7 @@ import { updateDaemonJson, updateDaemonJsonByfile, } from '@/api/modules/container'; +import { getSettingInfo } from '@/api/modules/setting'; import { MsgSuccess } from '@/utils/message'; import { checkNumberRange } from '@/global/form-rules'; @@ -271,6 +284,7 @@ const confirmDialogRefIptable = ref(); const confirmDialogRefIpv6 = ref(); const logOptionShow = ref(); const ipv6OptionShow = ref(); +const sockPathRef = ref(); const form = reactive({ isSwarm: false, @@ -290,12 +304,13 @@ const form = reactive({ logOptionShow: false, logMaxSize: '', logMaxFile: 3, + + dockerSockPath: '', }); const rules = reactive({ logMaxSize: [checkNumberRange(1, 1024000)], logMaxFile: [checkNumberRange(1, 100)], }); - const formRef = ref(); const dockerConf = ref(); const confirmDialogRefFile = ref(); @@ -318,6 +333,10 @@ const onChangeRegistries = () => { registriesRef.value.acceptParams({ registries: form.registries }); }; +const onChangeSockPath = () => { + sockPathRef.value.acceptParams({ dockerSockPath: form.dockerSockPath }); +}; + const handleIPv6 = async () => { if (form.ipv6) { ipv6OptionRef.value.acceptParams({ @@ -496,6 +515,9 @@ const search = async () => { form.fixedCidrV6 = res.data.fixedCidrV6; form.ip6Tables = res.data.ip6Tables; form.experimental = res.data.experimental; + + const settingRes = await getSettingInfo(); + form.dockerSockPath = settingRes.data.dockerSockPath || 'unix:///var/run/docker-x.sock'; }; onMounted(() => { diff --git a/frontend/src/views/container/setting/sock-path/index.vue b/frontend/src/views/container/setting/sock-path/index.vue new file mode 100644 index 000000000..0338f1292 --- /dev/null +++ b/frontend/src/views/container/setting/sock-path/index.vue @@ -0,0 +1,116 @@ + + + + + + + + + + + + + + + + {{ $t('container.sockPathHelper1') }} + + + + + + + {{ $t('commons.button.cancel') }} + + {{ $t('commons.button.confirm') }} + + + + + + +