diff --git a/server/docker.js b/server/docker.js index 177fa6cb6..ff2315027 100644 --- a/server/docker.js +++ b/server/docker.js @@ -75,7 +75,7 @@ class DockerHost { if (dockerHost.dockerType === "socket") { options.socketPath = dockerHost.dockerDaemon; } else if (dockerHost.dockerType === "tcp") { - options.baseURL = dockerHost.dockerDaemon; + options.baseURL = DockerHost.patchDockerURL(dockerHost.dockerDaemon); } let res = await axios.request(options); @@ -99,6 +99,18 @@ class DockerHost { } } + + /** + * Since axios 0.27.X, it does not accept `tcp://` protocol. + * Change it to `http://` on the fly in order to fix it. (https://github.com/louislam/uptime-kuma/issues/2165) + */ + static patchDockerURL(url) { + if (typeof url === "string") { + // Replace the first occurrence only with g + return url.replace(/tcp:\/\//g, "http://"); + } + return url; + } } module.exports = { diff --git a/server/model/monitor.js b/server/model/monitor.js index f96b4df06..ac8925608 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -17,6 +17,7 @@ const version = require("../../package.json").version; const apicache = require("../modules/apicache"); const { UptimeKumaServer } = require("../uptime-kuma-server"); const { CacheableDnsHttpAgent } = require("../cacheable-dns-http-agent"); +const { DockerHost } = require("../docker"); /** * status: @@ -498,7 +499,7 @@ class Monitor extends BeanModel { if (dockerHost._dockerType === "socket") { options.socketPath = dockerHost._dockerDaemon; } else if (dockerHost._dockerType === "tcp") { - options.baseURL = dockerHost._dockerDaemon; + options.baseURL = DockerHost.patchDockerURL(dockerHost._dockerDaemon); } log.debug(`[${this.name}] Axios Request`); diff --git a/server/socket-handlers/docker-socket-handler.js b/server/socket-handlers/docker-socket-handler.js index 5a53494db..542f18cef 100644 --- a/server/socket-handlers/docker-socket-handler.js +++ b/server/socket-handlers/docker-socket-handler.js @@ -56,7 +56,7 @@ module.exports.dockerSocketHandler = (socket) => { let amount = await DockerHost.testDockerHost(dockerHost); let msg; - if (amount > 1) { + if (amount >= 1) { msg = "Connected Successfully. Amount of containers: " + amount; } else { msg = "Connected Successfully, but there are no containers?"; diff --git a/src/components/DockerHostDialog.vue b/src/components/DockerHostDialog.vue index 92a8ce455..50ffa49c1 100644 --- a/src/components/DockerHostDialog.vue +++ b/src/components/DockerHostDialog.vue @@ -30,7 +30,8 @@ {{ $t("Examples") }}: