MongoDB with Replica Sets enabled: container exits with code 0 and restarts in a loop (generated startup script never waits on mongod)
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 68/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- bash, docker, mongodb, typescript
Direzione di ricerca
Leggi packages/server/src/utils/databases/mongo.ts intorno alla riga 84 e segui come la scheda Advanced salva un valore Command vuoto in apps/dokploy/components/dashboard/postgres/advanced/show-custom-command.tsx. Controlla come lo script di avvio generato per il replica set gestisce un Command vuoto; il problema segnalato è che termina dopo l’inizializzazione invece di mantenere mongod in esecuzione. Il lavoro è completato quando lo script mantiene il task in esecuzione se Command è vuoto e la riproduzione segnalata con MongoDB 8.0 e replica set non entra più in un ciclo.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
To Reproduce
- Create a MongoDB database in Dokploy with Replica Sets enabled.
- Set the image to
mongo:8.0on the Advanced tab and save. Leave Command and Args empty. - Deploy.
- Run
docker service ps <appName> --no-truncon the server.
Current vs. Expected behavior
Expected: one task stays Running, with mongod as a long-lived process.
Actual: the service restarts in a loop about every 13 seconds.
docker service ps <appName> --no-truncshows a new task every ~13 s, each endingShutdown/Complete.docker ps -ashowsExited (0).- mongod logs a healthy startup each time (becomes PRIMARY, "startup complete", no fatal errors). The container log then ends with
Replica set already initialized.and the container exits.
docker service inspect shows Command: ["/bin/bash"] with a -c script. Redacted copy of the generated script:
#!/bin/bash
mongod --port 27017 --replSet rs0 --bind_ip_all &
MONGOD_PID=$!
# Wait for MongoDB to be ready
while ! mongosh --eval "db.adminCommand('ping')" > /dev/null 2>&1; do
sleep 2
done
# Check if replica set is already initialized
REPLICA_STATUS=$(mongosh --quiet --eval "rs.status().ok || 0")
if [ "$REPLICA_STATUS" != "1" ]; then
echo "Initializing replica set..."
mongosh --eval '
rs.initiate({
_id: "rs0",
members: [{ _id: 0, host: "<appName>:27017", priority: 1 }]
});
while (!rs.isMaster().ismaster) { sleep(1000); }
db.getSiblingDB("admin").createUser({
user: "<REDACTED>",
pwd: "<REDACTED>",
roles: ["root"]
});
'
else
echo "Replica set already initialized."
fi
The script ends after the if/else. There is no wait $MONGOD_PID at the end, so bash (PID 1) exits with code 0 and mongod is killed with it.
Likely cause (hypothesis, from reading the source): in packages/server/src/utils/databases/mongo.ts#L84, the last line of the script is:
${command ?? "wait $MONGOD_PID"}
The Advanced tab form (show-custom-command.tsx#L138) saves command: "" when the field is left empty. "" ?? "wait $MONGOD_PID" evaluates to "", so the wait line is dropped. I think this is why it works for some users: the bug only appears once that form has been saved, for example to change the image. A database whose command is still NULL keeps the wait.
Possible fix: use command || "wait $MONGOD_PID", or command?.trim() ? command : "wait $MONGOD_PID". Saving null from the form when Command is empty would also work.
Workaround: set Command on the Advanced tab to:
trap 'kill -TERM $MONGOD_PID' TERM INT; wait $MONGOD_PID; wait $MONGOD_PID
After that, one task stays Running. docker service update --force <appName> gives a clean Shutdown of the old task (not Failed) and a healthy new one.
Setting Command to mongod makes things worse. With replica sets on, Command replaces the final wait line of the script instead of the container command. A second mongod starts and fails with "Address already in use" (exit code 48).
Provide environment information
Operating System:
OS: Ubuntu 24.04.5 LTS
Arch: x86_64
Dokploy version: v0.31.4
VPS Provider: Contabo
Docker: 29.9.3
Swarm: active
What applications/services are you trying to deploy?
MongoDB (mongo:8.0) with Replica Sets enabled
Which area(s) are affected? (Select all that apply)
Databases
Are you deploying the applications where Dokploy is installed or on a remote server?
Same server where Dokploy is installed
Additional context
Related observations. I can file these separately if you prefer:
- The Command field means something different with Replica Sets on. It replaces the script's final
wait $MONGOD_PIDline instead of the container command. Nothing in the UI says so. - Credentials are not enforced in replica-set mode. mongod is started directly with
--port 27017 --replSet rs0 --bind_ip_all, with no--author--keyFile. The root user is created, but the log says "Access control is not enabled for the database", and unauthenticatedmongoshcan list databases. Users who enter credentials in the UI will expect them to be enforced. - The root password is embedded in the service spec in plain text (visible via
docker service inspect, in the-cscript). It is also interpolated inside a single-quoted bash string, so (hypothesis, untested) a password containing'would break the script.
Will you send a PR to fix it?
Maybe. I may be able to send a one-line fix if I have time, but I'm not sure yet.
- Lingua principale
- TypeScript
- Stelle
- 38.8k
- Fork
- 3.2k
- Merge medio
- 1g 10h
- PR unite (30g)
- 110
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Include un Dockerfile o un file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di Dokploy/dokploy
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
Dokploy/dokploy#6151 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Healthy Swarm task shows an empty `(Error:)` suffix on the last row of the Containers tabForse già presa @AyhamJo7 l’ha presa 4 giorni fa. Apertaneeds-triage🔍
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
Dokploy/dokploy#6115 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Global search (Cmd/Ctrl+J) never sorts results by relevanceForse già presa @hamidzr l’ha presa 6 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
Dokploy/dokploy#6107 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
`utils/dns/ovh.ts`: the zone-listing 403 handler replaces the provider's error instead of chaining itForse già presa @SyncWithRaj l’ha presa 8 giorni fa. Apertabug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 84/100
Dokploy/dokploy#6075 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Dokploy monitoring API returns partial container metrics with HTTP 200 when a row read failsForse già presa @PAtreju l’ha presa 12 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
Dokploy/dokploy#6029 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di Dokploy/dokploy
Issue simili
-
[Bug]: RUN_STARTED resets the run's tool-call tally even when a subscriber suppresses the eventApertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
ag-ui-protocol/ag-ui#3504 ·
I maintainer di solito rispondono entro 1 giorno
-
area/profiles area/sessions comp/desktop desktop/chat desktop/sessions P2 type/bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
NousResearch/hermes-agent#161712 ·
I maintainer di solito rispondono entro 1 giorno
-
bug p3
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
rothgar/rabble.radio#283 ·
I maintainer di solito rispondono entro 1 giorno
-
bug from-app needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
nightly-labs/openbot#19805 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
OHDSI/Data2Evidence#3760 ·
I maintainer di solito rispondono entro 3 giorni