Dockerfile change.

Daan committed Mar 23, 2025 at 21:02 UTC 62443dd4f48bb43d9da4807346dfbcc170706e5a
2 files changed +185 -132
docker/Dockerfile
+14 -8
@@ -17,13 +17,19 @@ RUN if [ -z "$DISABLE_MINIFY" ] || [ -z "$DISABLE_TRANSLATE" ]; then \
17 cd translate && \
18 node translate.js extractall && \
19 \
20 - if [ -z "$DISABLE_MINIFY" ]; then \
21 - node translate.js minifyall; \
22 - fi; \
20 + case "$DISABLE_MINIFY" in \
21 + false|no|FALSE|NO) \
22 + node translate.js minifyall;; \
23 + *) \
24 + echo "Setting MINIFY as disabled.";; \
25 + esac \
26 \
24 - if [ -z "$DISABLE_TRANSLATE" ]; then \
25 - node translate.js translateall; \
26 - fi \
27 + case "$DISABLE_TRANSLATE" in \
28 + false|no|FALSE|NO) \
29 + node translate.js translateall;; \
30 + *) \
31 + echo "Setting TRANSLATE as disabled.";; \
32 + esac \
33 fi
34 # Possible more updated alternative? @minify-html/node@0.15.0 -> https://www.npmjs.com/package/@minify-html/node
35
@@ -53,7 +59,7 @@ ENV LOCALSESSIONRECORDING="true"
59 ENV MINIFY="true"
60 ENV REGENSESSIONKEY="false"
61 ENV REVERSE_PROXY=""
56 -ENV REVERSE_PROXY_TLS_PORT=""
62 +ENV REVERSE_PROXY_TLS_PORT="443"
63 ENV WEBRTC="false"
64
65
@@ -170,4 +176,4 @@ VOLUME /opt/meshcentral/meshcentral-backups
176 COPY ./docker/entrypoint.sh ./entrypoint.sh
177 COPY ./docker/config.json.template /opt/meshcentral/config.json.template
178
173 -CMD ["bash", "/opt/meshcentral/entrypoint.sh"]
\ No newline at end of file
179 +ENTRYPOINT ["bash", "/opt/meshcentral/entrypoint.sh"]
\ No newline at end of file
docker/README.md
+171 -124
@@ -1,138 +1,185 @@
1 -# Create folder-structure and files
1 +# MeshCentral Docker Configuration Guide
2 +
3 +## Overview
4 +This document provides a comprehensive guide to setting up and configuring MeshCentral in a Docker environment. It includes available options, security measures, and deployment instructions.
5 +
6 +## Environment Variables
7 +Below is a breakdown of environment variables used in this setup.
8 +
9 +### General MeshCentral Configuration
10 +| Variable | Default Value | Description |
11 +|----------|--------------|-------------|
12 +| NODE_ENV | production | Specifies the Node.js environment. |
13 +| CONFIG_FILE | /opt/meshcentral/meshcentral-data/config.json | Path to the configuration file. |
14 +| DYNAMIC_CONFIG | true | Enables/disables dynamic configuration. This means config is being rechecked every container restart. |
15 +| ALLOWPLUGINS | false | Enables/disables plugins. |
16 +| ALLOW_NEW_ACCOUNTS | false | Enables/disables new account creation. |
17 +| ALLOWED_ORIGIN | false | Enables/disables allowed origin policy. |
18 +| ARGS | "" | Additional arguments for MeshCentral. |
19 +| HOSTNAME | localhost | Specifies the hostname. |
20 +| IFRAME | false | Enables/disables embedding in an iframe. |
21 +| LOCALSESSIONRECORDING | true | Enables session recording. |
22 +| MINIFY | true | Minifies the JavaScript and HTML output. |
23 +| REGENSESSIONKEY | false | Regenerates the session key on each restart of the container. |
24 +| REVERSE_PROXY | "" | Configures reverse proxy support through `certUrl`. |
25 +| REVERSE_PROXY_TLS_PORT | "443" | Configures reverse proxy TLS port, will be combined with: `REVERSE_PROXY`. |
26 +| WEBRTC | false | Enables/disables WebRTC support. |
27 +
28 +### Database Configuration
29 +
30 +#### MeshCentral Database Settings
31 +| Variable | Default Value | Description |
32 +|----------|--------------|-------------|
33 +| USE_MONGODB | false | Enables MongoDB usage. |
34 +| USE_POSTGRESQL | false | Enables PostgreSQL usage. |
35 +| USE_MARIADB | false | Enables MariaDB usage. |
36 +
37 +#### MongoDB Configuration
38 +| Variable | Default Value | Description |
39 +|----------|--------------|-------------|
40 +| MONGO_HOST | "" | MongoDB server hostname. |
41 +| MONGO_PORT | 27017 | MongoDB server port. |
42 +| MONGO_USERNAME | "" | MongoDB username. |
43 +| MONGO_PASS | "" | MongoDB password. |
44 +| MONGO_URL | "" | Overrides other MongoDB connection settings. |
45 +
46 +#### PostgreSQL Configuration
47 +| Variable | Default Value | Description |
48 +|----------|--------------|-------------|
49 +| PSQL_HOST | "" | PostgreSQL server hostname. |
50 +| PSQL_PORT | 5432 | PostgreSQL server port. |
51 +| PSQL_USER | "" | PostgreSQL username. |
52 +| PSQL_PASS | "" | PostgreSQL password. |
53 +| PSQL_DATABASE | "" | PostgreSQL database name. |
54 +
55 +#### MariaDB Configuration
56 +| Variable | Default Value | Description |
57 +|----------|--------------|-------------|
58 +| MARIADB_HOST | "" | MariaDB server hostname. |
59 +| MARIADB_PORT | 3306 | MariaDB server port. |
60 +| MARIADB_USER | "" | MariaDB username. |
61 +| MARIADB_PASS | "" | MariaDB password. |
62 +| MARIADB_DATABASE | "" | MariaDB database name. |
63 +
64 +## Deployment Instructions
65 +
66 +### Running with Docker CLI
67 +```sh
68 +docker run -d \
69 + -e HOSTNAME=myserver.domain.com \
70 + -e ALLOW_NEW_ACCOUNTS=true \
71 + -e USE_MONGODB=true \
72 + -e MONGO_HOST=mongodb \
73 + -e MONGO_PORT=27017 \
74 + -v meshcentral-data:/opt/meshcentral/meshcentral-data \
75 + -p 443:443 \
76 + ghcr.io/ylianst/meshcentral:<tag>
77 +```
78
3 -# TO BE REWRITTEN - In progress, for questions: dselen@nerthus.nl or @DaanSelen.
79 +### Running with Docker Compose
80 +```yaml
81 +services:
82 + meshcentral:
83 + image: ghcr.io/ylianst/meshcentral:<tag>
84 + environment:
85 + - HOSTNAME=myserver.domain.com
86 + - ALLOW_NEW_ACCOUNTS=true
87 + - USE_MONGODB=true
88 + - MONGO_HOST=mongodb
89 + - MONGO_PORT=27017
90 + volumes:
91 + - meshcentral-data:/opt/meshcentral/meshcentral-data
92 + ports:
93 + - "443:443"
94 +volumes:
95 + meshcentral-data:
96 +```
97
98 +### Using an `.env` File
99 +Create a `.env` file:
100 +```ini
101 +# Environment variables
102 +NODE_ENV=production
103 +CONFIG_FILE=/opt/meshcentral/meshcentral-data/config.json
104 +DYNAMIC_CONFIG=true
105 +
106 +# MeshCentral Configuration
107 +ALLOWPLUGINS=false
108 +ALLOW_NEW_ACCOUNTS=false
109 +ALLOWED_ORIGIN=false
110 +ARGS=
111 +HOSTNAME=localhost
112 +IFRAME=false
113 +LOCALSESSIONRECORDING=true
114 +MINIFY=true
115 +REGENSESSIONKEY=false
116 +REVERSE_PROXY=
117 +REVERSE_PROXY_TLS_PORT=
118 +WEBRTC=false
119 +
120 +# MongoDB Configuration
121 +USE_MONGODB=false
122 +MONGO_HOST=
123 +MONGO_PORT=27017
124 +MONGO_USERNAME=
125 +MONGO_PASS=
126 +MONGO_URL=
127 +
128 +# PostgreSQL Configuration
129 +USE_POSTGRESQL=false
130 +PSQL_HOST=
131 +PSQL_PORT=5432
132 +PSQL_USER=
133 +PSQL_PASS=
134 +PSQL_DATABASE=
135 +
136 +# MariaDB/MySQL Configuration
137 +USE_MARIADB=false
138 +MARIADB_HOST=
139 +MARIADB_PORT=3306
140 +MARIADB_USER=
141 +MARIADB_PASS=
142 +MARIADB_DATABASE=
143 +
144 +# Build options
145 +INCLUDE_MONGODB_TOOLS=false
146 +INCLUDE_POSTGRESQL_TOOLS=false
147 +INCLUDE_MARIADB_TOOLS=false
148 +PREINSTALL_LIBS=false
149 ```
6 -| - meshcentral/ # this folder contains the persistent data
7 - | - data/ # MeshCentral data-files
8 - | - user_files/ # where file uploads for users live
9 - | - web/ # location for site customization files
10 - | - backup/ # location for the meshcentral-backups
11 -| - .env # environment file with initial variables
12 -| - docker-compose.yml
150 +Then run Docker Compose:
151 +```sh
152 +docker-compose --env-file .env up -d
153 ```
154
15 -# Templates
16 -
17 -## .env
18 -You can place the `config.json` file directly under `./meshcentral/data/`, or use the following `.env` file instead.
155 +# MeshCentral Docker Build Process
156
20 -```ini
21 -NODE_ENV = "production"
22 -# Leave CONFIG_FILE as per default by using this, or removing it completely from the list. Otherwise if you know what you are doing, you can use this.
23 -CONFIG_FILE = "/opt/meshcentral/meshcentral-data/config.json"
24 -# DYNAMIC_CONFIG enables the config to be rechecked on every restart. If disabled then the container runtime will not change the config.json.
25 -DYNAMIC_CONFIG = "true"
26 -
27 -# Environment variables for the MeshCentral Config.json
28 -ALLOWPLUGINS = "false"
29 -ALLOW_NEW_ACCOUNTS = "false"
30 -ALLOWED_ORIGIN = "false"
31 -ARGS = ""
32 -HOSTNAME = "localhost"
33 -IFRAME = "false"
34 -LOCALSESSIONRECORDING = "true"
35 -MINIFY = "true"
36 -REGENSESSIONKEY = "false"
37 -REVERSE_PROXY = ""
38 -REVERSE_PROXY_TLS_PORT = ""
39 -WEBRTC = "false"
40 -
41 -# MongoDB Variables
42 -INCLUDE_MONGODB_TOOLS = "false"
43 -USE_MONGODB = "false"
44 -MONGO_HOST = ""
45 -MONGO_PORT = "27017"
46 -MONGO_USERNAME = ""
47 -MONGO_PASS = ""
48 -MONGO_URL = ""
49 -
50 -# PostgreSQL Variables
51 -INCLUDE_POSTGRESQL_TOOLS = "false"
52 -USE_POSTGRESQL = "false"
53 -PSQL_HOST = ""
54 -PSQL_PORT = "5432"
55 -PSQL_USER = ""
56 -PSQL_PASS = ""
57 -PSQL_DATABASE = ""
58 -
59 -# MariaDB/MySQL Variables (Alpine Linux only provides MariaDB binaries)
60 -INCLUDE_MARIADB_TOOLS = "false"
61 -USE_MARIADB = "false"
62 -MARIADB_HOST = ""
63 -MARIADB_PORT = "3306"
64 -MARIADB_USER = ""
65 -MARIADB_PASS = ""
66 -MARIADB_DATABASE = ""
67 -```
157 +This document explains the build process for the MeshCentral Docker image, along with details on various build arguments and how to use them.
158
69 -## docker-compose.yml
159 +## Build Arguments
160
71 -```yaml
72 -services:
73 - meshcentral:
74 - restart: always
75 - container_name: meshcentral
76 - # use the official meshcentral container
77 - image: ghcr.io/ylianst/meshcentral:latest
78 - ports:
79 - - 8086:443
80 - env_file:
81 - - .env
82 - volumes:
83 - # config.json and other important files live here. A must for data persistence
84 - - ./meshcentral/data:/opt/meshcentral/meshcentral-data
85 - # where file uploads for users live
86 - - ./meshcentral/user_files:/opt/meshcentral/meshcentral-files
87 - # location for the meshcentral-backups - this should be mounted to an external storage
88 - - ./meshcentral/backup:/opt/meshcentral/meshcentral-backups
89 - # location for site customization files
90 - - ./meshcentral/web:/opt/meshcentral/meshcentral-web
91 -```
161 +The following build arguments are available for customizing the build process:
162
93 -## docker-compose.yml mongodb
163 +- **DISABLE_MINIFY**: Disable HTML/JS minification during the build.
164 +- **DISABLE_TRANSLATE**: Disable translation of strings in MeshCentral.
165 +- **INCLUDE_MONGODB_TOOLS**: Include MongoDB client and related tools.
166 +- **INCLUDE_POSTGRESQL_TOOLS**: Include PostgreSQL client tools.
167 +- **INCLUDE_MARIADB_TOOLS**: Include MariaDB/MySQL client tools.
168 +- **PREINSTALL_LIBS**: Pre-install specific libraries like `ssh2`, `semver`, `nodemailer`, etc.
169
95 -```yaml
96 -version: '3'
170 +### Build Commands with Arguments
171
98 -networks:
99 - meshcentral-tier:
100 - driver: bridge
172 +Here are the shell commands to build the Docker image with different configurations.
173
102 -services:
103 - mongodb:
104 - restart: always
105 - container_name: mongodb
106 - image: mongo:latest
107 - env_file:
108 - - .env
109 - volumes:
110 - # mongodb data-directory - A must for data persistence
111 - - ./meshcentral/mongodb_data:/data/db
112 - networks:
113 - - meshcentral-tier
174 +#### 1. Build with Minify and Translate Disabled
175 +If you want to disable both HTML/JS minification and translation during the build process, use the following command:
176
115 - meshcentral:
116 - restart: always
117 - container_name: meshcentral
118 - # use the official meshcentral container
119 - image: ghcr.io/ylianst/meshcentral:latest
120 - depends_on:
121 - - mongodb
122 - ports:
123 - # MeshCentral will moan and try everything not to use port 80, but you can also use it if you so desire, just change the config.json according to your needs
124 - - 8086:443
125 - env_file:
126 - - .env
127 - volumes:
128 - # config.json and other important files live here. A must for data persistence
129 - - ./meshcentral/data:/opt/meshcentral/meshcentral-data
130 - # where file uploads for users live
131 - - ./meshcentral/user_files:/opt/meshcentral/meshcentral-files
132 - # location for the meshcentral-backups - this should be mounted to an external storage
133 - - ./meshcentral/backup:/opt/meshcentral/meshcentral-backups
134 - # location for site customization files
135 - - ./meshcentral/web:/opt/meshcentral/meshcentral-web
136 - networks:
137 - - meshcentral-tier
177 +```sh
178 +docker build --build-arg DISABLE_MINIFY=no --build-arg DISABLE_TRANSLATE=no -t meshcentral .
179 ```
180 +
181 +## Security Measures
182 +- Only exposing port 443 to minimize attack surface.
183 +- Using environment variables for sensitive credentials.
184 +- Removing unnecessary files after installation.
185 +- Enforcing proper permissions on configuration files.
\ No newline at end of file