Add ports in docker for setup without editing config file (#7569)

* Add ports in docker * Fix ports in debian docker

Diogo Carvalho committed Jan 22, 2026 at 08:52 UTC 3a888ae87aff8cf0852ecc8391f8eb0e84519594
5 files changed +44 -4
docker/Dockerfile
+4 -1
@@ -79,6 +79,8 @@ ENV ALLOW_PLUGINS="false" \
79 ALLOW_NEW_ACCOUNTS="false" \
80 ALLOWED_ORIGIN="false" \
81 HOSTNAME="localhost" \
82 + PORT="443" \
83 + REDIR_PORT="80" \
84 INSTALL_STYLISHUI="false" \
85 IFRAME="false" \
86 LOCAL_SESSION_RECORDING="true" \
@@ -198,7 +200,8 @@ RUN cd meshcentral \
200 && npm cache clean --force
201
202 # Expose needed ports
201 -EXPOSE 80 443
203 +EXPOSE ${PORT}
204 +EXPOSE ${REDIR_PORT}
205
206 # These volumes will be created by default even without any declaration, this allows default persistence in Docker/Podman. Dummy-proofing.
207 VOLUME /opt/meshcentral/meshcentral-data
docker/Dockerfile-debian
+4 -1
@@ -105,6 +105,8 @@ ENV ALLOW_PLUGINS="false" \
105 ALLOW_NEW_ACCOUNTS="false" \
106 ALLOWED_ORIGIN="false" \
107 HOSTNAME="localhost" \
108 + PORT="443" \
109 + REDIR_PORT="80" \
110 INSTALL_STYLISHUI="false" \
111 IFRAME="false" \
112 LOCAL_SESSION_RECORDING="true" \
@@ -225,7 +227,8 @@ RUN cd meshcentral \
227 && npm cache clean --force
228
229 # Expose needed ports
228 -EXPOSE 80 443
230 +EXPOSE ${PORT}
231 +EXPOSE ${REDIR_PORT}
232
233 # These volumes will be created by default even without any declaration, this allows default persistence in Docker/Podman. Dummy-proofing.
234 VOLUME /opt/meshcentral/meshcentral-data
docker/README.md
+4
@@ -52,6 +52,8 @@ Below is a breakdown of environment variables used in this setup.
52 | ALLOWED_ORIGIN | false | Enables/disables allowed origin policy. |
53 | ARGS | "" | Additional arguments for MeshCentral. |
54 | HOSTNAME | localhost | Specifies the hostname. |
55 +| PORT | 443 | Specifies the port. |
56 +| REDIR_PORT | 80 | Specifies the redirection port. |
57 | IFRAME | false | Enables/disables embedding in an iframe. |
58 | LOCAL_SESSION_RECORDING | true | Enables session recording. |
59 | MINIFY | true | Minifies the JavaScript and HTML output. |
@@ -149,6 +151,8 @@ ALLOW_NEW_ACCOUNTS=false
151 ALLOWED_ORIGIN=false
152 ARGS=
153 HOSTNAME=localhost
154 +PORT=443
155 +REDIR_PORT=80
156 IFRAME=false
157 LOCAL_SESSION_RECORDING=true
158 MINIFY=true
docker/compose.yaml
+4 -2
@@ -4,6 +4,8 @@ services:
4 environment:
5 - DYNAMIC_CONFIG=false # Show the option but disable it by default, for safety.
6 - HOSTNAME=myserver.domain.com # Set the hostname in the config.json
7 + - PORT=443 # Set the port in the config.json
8 + - REDIR_PORT=80 # Set the redirection port in the config.json
9 - ALLOW_NEW_ACCOUNTS=false # Disable creation of new accounts (except for the first user) in the config.json
10 - USE_MONGODB=true # Enable the Mongo connector in the config.json
11 - MONGO_URL=mongodb://username:password@mongodb:27017/meshcentral # Example MONGO_URL
@@ -13,8 +15,8 @@ services:
15 - meshcentral-web:/opt/meshcentral/meshcentral-web
16 - meshcentral-backups:/opt/meshcentral/meshcentral-backups
17 ports:
16 - - "80:80"
17 - - "443:443"
18 + - ${PORT}:${PORT}
19 + - ${REDIR_PORT}:${REDIR_PORT}
20 volumes:
21 meshcentral-data:
22 meshcentral-files:
docker/entrypoint.sh
+28
@@ -122,6 +122,34 @@ function dynamic_config() {
122 "$CONFIG_FILE" > temp_config.json && mv temp_config.json "$CONFIG_FILE"
123 fi
124
125 + # PORT
126 + if [[ -n $PORT ]]; then
127 + echo "Setting port... $PORT"
128 +
129 + jq --arg port "$PORT" \
130 + '.settings.port = $port' \
131 + "$CONFIG_FILE" > temp_config.json && mv temp_config.json "$CONFIG_FILE"
132 + else
133 + echo "Invalid or no port, defaulting to '443', value given: $PORT"
134 + jq --arg port "443" \
135 + '.settings.port = $port' \
136 + "$CONFIG_FILE" > temp_config.json && mv temp_config.json "$CONFIG_FILE"
137 + fi
138 +
139 + # REDIR_PORT
140 + if [[ -n $REDIR_PORT ]]; then
141 + echo "Setting redirport... $REDIR_PORT"
142 +
143 + jq --arg redirport "$REDIR_PORT" \
144 + '.settings.redirPort = $redirport' \
145 + "$CONFIG_FILE" > temp_config.json && mv temp_config.json "$CONFIG_FILE"
146 + else
147 + echo "Invalid or no redirport, defaulting to '80', value given: $REDIR_PORT"
148 + jq --arg redirport "80" \
149 + '.settings.redirPort = $redirport' \
150 + "$CONFIG_FILE" > temp_config.json && mv temp_config.json "$CONFIG_FILE"
151 + fi
152 +
153 # ALLOWPLUGINS
154 ALLOW_PLUGINS=${ALLOW_PLUGINS,,}
155 if [[ $ALLOW_PLUGINS =~ ^(true|false)$ ]]; then