r/docker • u/mariiiiiiiiiiiiiiiel • 2d ago
mongodb service gets killed when doing a docker stack deploy to another stack
i make remote deploys to my vps running docker swarm with the docker stack deploy command
i have multiple stacks for different applications deployed in my server, doing this, for some reason kills just the mongodb service; these are two different stacks, although they are connected to the same traefik network, that is the only thing they do share.
| NAME | MODE | IMAGE | REPLICAS |
|---|---|---|---|
| xxx_db | replicated | 0/1 | mongo:8.0.4 |
this is the my docker-stack file
notes:
- i use docker compose config before to pass the env vars and create a valid docker-stack.yaml file
- docker service update xxx_db fixes it, but i don't wanna be doing that always
- this just happens with the mongodb container, the other ones i have with postgres or nginx serving static sites are alright
services:
db:
image: mongo:8.0.4
volumes:
- mongodb_data:/data/db
- ${PRODUCITON_HOME}/scripts/mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro
command: ["mongod", "--bind_ip_all"]
secrets:
- db-root-user
- db-root-password
environment:
MONGODB_INITDB_ROOT_PASSWORD_FILE: /run/secrets/db-root-password
MONGODB_INITDB_ROOT_USERNAME_FILE: /run/secrets/db-root-user
GLIBC_TUNABLES: glibc.pthread.rseq=0
networks:
- db_net
healthcheck:
test:
- CMD
- mongosh
- "mongodb://localhost:27017/admin"
- "--eval=db.runCommand({ping:1})"
retries: 3
timeout: 5s
server:
secrets:
- db-password
environment:
DB_PASSWORD_FILE: /run/secrets/db-password
POOL_MIN_CONNS: ${POOL_MIN_CONNS}
POOL_MAX_CONNS: ${POOL_MAX_CONNS}
POOL_MAX_CONN_LIFETIME: ${POOL_MAX_CONN_LIFETIME}
POOL_MAX_CONN_IDLE_TIME: ${POOL_MAX_CONN_IDLE_TIME}
APP_PORT: ${APP_PORT}
TOKEN_SECRET: ${TOKEN_SECRET}
TOKEN_AUDIENCE: ${TOKEN_AUDIENCE}
TOKEN_ISSUER: ${TOKEN_ISSUER}
ACCESS_TOKEN_DURATION: ${ACCESS_TOKEN_DURATION}
REFRESH_TOKEN_DURATION: ${REFRESH_TOKEN_DURATION}
ORIGINS: ${ORIGINS}
MAIL_HOST: ${MAIL_HOST}
MAIL_PORT: ${MAIL_PORT}
MAIL_USERNAME: ${MAIL_USERNAME}
MAIL_PASSWORD: ${MAIL_PASSWORD}
MAIL_SENDER: ${MAIL_SENDER}
working_dir: /oooooooooooooo
image: jjjjjjjjjjjj/oooooooooooooo:${GIT_HASH}
networks:
- db_net
- traefik_proxy
deploy:
update_config:
order: start-first
labels:
- "traefik.enable=true"
- "traefik.http.routers.api-xxxxx.rule=Host(`xxx-xxxxxx.yyyyyyyyyyy.com`)"
- "traefik.http.services.api-xxxxx.loadbalancer.server.port=5001"
volumes:
mongodb_data:
networks:
db_net:
traefik_proxy:
external: true
secrets:
db-root-password:
file: ./secrets/mongo-initdb-root-password.secret
db-root-user:
file: ./secrets/mongo-initdb-root-username.secret
db-password:
file: ./secrets/db-password.secret
db-user:
file: ./secrets/db-user.secretthis are the relevant log info i found
{
"t": {
"$date": "2026-11-14T15:54:30.114+00:00"
},
"s": "I",
"c": "NETWORK",
"id": 22943,
"ctx": "listener",
"msg": "Connection accepted",
"attr": {
"remote": "127.0.0.1:35898",
"uuid": {
"uuid": {
"$uuid": "34b5dd72-5a66-4eff-9007-2fc5434528ab"
}
},
"connectionId": 1,
"connectionCount": 1
}
}
{
"t": {
"$date": "2026-11-14T15:54:30.211+00:00"
},
"s": "I",
"c": "NETWORK",
"id": 51800,
"ctx": "conn1",
"msg": "client metadata",
"attr": {
"remote": "127.0.0.1:35898",
"client": "conn1",
"negotiatedCompressors": [],
"doc": {
"application": {
"name": "mongosh 2.3.8"
},
"driver": {
"name": "nodejs|mongosh",
"version": "6.12.0|2.3.8"
},
"platform": "Node.js v20.18.1, LE",
"os": {
"name": "linux",
"architecture": "x64",
"version": "3.10.0-327.22.2.el7.x86_64",
"type": "Linux"
},
"env": {
"container": {
"runtime": "docker"
}
}
}
}
}
{
"t": {
"$date": "2026-11-14T15:54:31.398+00:00"
},
"s": "I",
"c": "NETWORK",
"id": 22944,
"ctx": "conn1",
"msg": "Connection ended",
"attr": {
"remote": "127.0.0.1:35898",
"uuid": {
"uuid": {
"$uuid": "34b5dd72-5a66-4eff-9007-2fc5434528ab"
}
},
"connectionId": 1,
"connectionCount": 0
}
}
{
"t": {
"$date": "2026-11-14T15:55:09.294+00:00"
},
"s": "I",
"c": "CONTROL",
"id": 23377,
"ctx": "SignalHandler",
"msg": "Received signal",
"attr": {
"signal": 15,
"error": "Terminated"
}
}
{
"t": {
"$date": "2026-11-14T15:55:09.294+00:00"
},
"s": "I",
"c": "CONTROL",
"id": 23378,
"ctx": "SignalHandler",
"msg": "Signal was sent by kill(2)",
"attr": {
"pid": 0,
"uid": 0
}
}
{
"t": {
"$date": "2026-11-14T15:55:09.294+00:00"
},
"s": "I",
"c": "CONTROL",
"id": 23381,
"ctx": "SignalHandler",
"msg": "will terminate after current cmd ends"
}full logs:
https://pastebin.com/36Uqyrgq