Skip to content

Commit 0b9a436

Browse files
committed
adding support of custom DOCKER_SOCKET
issue #51
1 parent 65f52ca commit 0b9a436

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

README.md

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -101,34 +101,23 @@ List of environment variables for more customization:
101101
| CADVISOR_PORT | 8080 | |
102102
| ENABLE_DATA_API | true | Use this env to export the `/data` API that returns the swarm status as a JSON object. Note that it requires basic-auth if `ENABLE_AUTHENTICATION` is activated. |
103103
| ENABLE_NETWORKS | false | `true` by default, set to `false` to remove the network section from the dashboard. |
104+
| DOCKER_SOCKET | tcp://localhost:2375 | `/var/run/docker.sock` by default. You can use it with [docker-socket-proxy](https://github.com/Tecnativa/docker-socket-proxy). |
104105

105106
## Security
106107

107108
+ We redact docker event data before sending them to the client. The previous version was sending the whole docker event data, including environment variables (someone might have stored some passwords in them, by mistake!). So, please consider using the newer version.
108109

109110
+ Using the `ENABLE_AUTHENTICATION` environment variable, there is an option to use `Basic Auth`. The WebSocket server will close the connection if it does not receive a valid authentication token. See the example in the above section for more info.
110111

111-
+ Using the `ENABLE_HTTPS` environment variable, there is an option to use `HTTPS` and `WSS`. We have Let’s Encrypt integration with the DNS challenge. See the example in the above section for more info.
112-
113-
114-
## Production use
115-
116-
There are two considerations for any serious deployment of the dashboard:
117-
118-
1. Security - the dashboard node.js server has access to the docker daemon unix socket
119-
and runs on the manager, which makes it a significant attack surface (i.e. compromising
120-
the dashboard's node server would give an attacker full control of the swarm)
121-
2. The interaction with docker API is a fairly rough implementation and
122-
is not very optimized. The server polls the API every 1000 ms, publishing the
123-
response data to all open WebSockets if it changed since last time. There
124-
is probably a better way to look for changes in the Swarm that could be used
125-
in the future.
112+
+ Using the `ENABLE_HTTPS` environment variable, there is an option to use `HTTPS` and `WSS`. We have Let’s Encrypt integration with the DNS challenge. See the example for more info.
126113

114+
+ You can use [docker-socket-proxy](https://github.com/Tecnativa/docker-socket-proxy) with the `DOCKER_SOCKET` environment variable to minimize permissions and enhance security.
127115

128116
## Rough roadmap
129117

130118
* Show more service details (published port, image name, and version)
131119
* Node / Service / Task details panel
120+
* Improving performance by sending only the changes to online clients
132121

133122
Both feature requests and pull requests are welcome. If you want to build/test the code locally, see [commands.md](./test-cluster/commands.md) in the `test-cluster` directory.
134123

server/index.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const showTaskTimestamp = !(process.env.SHOW_TASK_TIMESTAMP === "false");
3030
const enableNetworks = !(process.env.ENABLE_NETWORKS === "false");
3131
const debugMode = process.env.DEBUG_MODE === "true";
3232
const enableDataAPI = process.env.ENABLE_DATA_API === "true";
33+
const dockerSocket = process.env.DOCKER_SOCKET || "/var/run/docker.sock";
3334

3435
const _nodeExporterServiceNameRegex = process.env.NODE_EXPORTER_SERVICE_NAME_REGEX || "";
3536
const useNodeExporter = _nodeExporterServiceNameRegex !== "";
@@ -65,12 +66,21 @@ function formatBytes(bytes, decimals = 0) {
6566
}
6667

6768
// Docker API integration
68-
6969
const dockerRequestBaseOptions = {
7070
method: 'GET',
71-
socketPath: '/var/run/docker.sock',
7271
};
73-
72+
if (dockerSocket.startsWith("tcp://")) {
73+
const regex = /^tcp:\/\/([^:]+):(\d+)$/;
74+
const match = dockerSocket.match(regex);
75+
if (match) {
76+
dockerRequestBaseOptions.host = match[1];
77+
dockerRequestBaseOptions.port = parseInt(match[2]);
78+
} else {
79+
console.log("error is parsing DOCKER_SOCKET");
80+
}
81+
} else {
82+
dockerRequestBaseOptions.socketPath = dockerSocket;
83+
}
7484
const dockerAPIRequest = path => {
7585
return new Promise((res, rej) => {
7686
let buffer = '';

0 commit comments

Comments
 (0)