[GH-ISSUE #562] Service keeps restarting with Docker Compose config #362

Closed
opened 2026-03-15 14:05:25 +03:00 by kerem · 6 comments
Owner

Originally created by @kylegillen on GitHub (Sep 3, 2025).
Original GitHub issue: https://github.com/axllent/mailpit/issues/562

Hi. Awesome product! Thanks for making it 😊

When running the example docker command in the terminal, it simply keeps restarting and seemingly exiting with code 0:

docker run -d \
--restart unless-stopped \
--name=mailpit \
-p 8025:8025 \
-p 1025:1025 \
axllent/mailpit

I've verified that there's nothing running on the same ports: lsof -i tcp:8025

I've gone hunting around github repos seeing if anyone has done anything different, but to no avail.
I'm not sure if there's a command that needs to be run to keep the service alive?

Adding tty: true to the service seems to keep it running, but doesn't make the GUI available at http://localhost:8025

I'm running macOSX 15.6.1 and using Docker desktop 4.45.0

I've installed the app via homebrew, and the GUI loads as expected.

Here's my full Docker related code for completeness (and just to confirm, I've also tried accessing the GUI via the port DOCKER_MAIL_CLIENT_PORT represents to no avail):

docker-compose.dev.yml
services:
  server:
    build:
      context: .
      dockerfile: Dockerfile.dev
    volumes:
      - /app/node_modules
      - .:/app
    depends_on:
      - database
      - valkey
      - mail
    command: >
      sh -c "pnpm start:dev"

  database:
    image: postgres:latest
    container_name: postgres
    restart: unless-stopped
    environment:
      POSTGRES_USER: '${DATABASE_USERNAME}'
      POSTGRES_PASSWORD: '${DATABASE_PASSWORD}'
      POSTGRES_DB: '${DATABASE_NAME}'
      TZ: 'UTC'
    ports:
      - ${DOCKER_DATABASE_PORT}:5432
    volumes:
      - ./.docker/postgres_data:/var/lib/postgresql/data
    networks:
      - network
  
  mail:
    image: axllent/mailpit:latest
    container_name: mail
    restart: unless-stopped
    volumes:
      - ./.docker/mailpit_data:/data
    ports:
      - ${DOCKER_MAIL_PORT}:1025
      - ${DOCKER_MAIL_CLIENT_PORT}:8025
    networks:
      - network
docker-compose.yml
services:
  server:
    container_name: server
    image: server:latest
    restart: unless-stopped
    env_file:
      - .env.local
    environment:
      DATABASE_HOST: '${DOCKER_DATABASE_HOST}'
      VALKEY_HOST: '${DOCKER_VALKEY_HOST}'
    ports:
      - ${APP_PORT}:${APP_PORT}
    networks:
      - network
    depends_on:
      - valkey
    
  valkey:
    image: valkey/valkey:latest
    container_name: valkey
    restart: unless-stopped
    ports:
      - ${DOCKER_VALKEY_PORT}:6379
    environment:
      VALKEY_PASSWORD: '${VALKEY_PASSWORD}'
      VALKEY_IO_THREADS: '${VALKEY_IO_THREADS}'
    volumes:
      - ./.docker/valkey_data:/data
    healthcheck:
      test: '[ $$(valkey-cli --pass "${VALKEY_PASSWORD}" ping) = ''PONG'' ]'
      start_period: 5s
      timeout: 3s
      interval: 1s
      retries: 5
    command:
      - sh
      - -c # this is to evaluate the $VALKEY_PASSWORD from the env
      - valkey-server --appendonly yes --requirepass $$VALKEY_PASSWORD --io-threads $$VALKEY_IO_THREADS --save "" ## $$ because of docker-compose
    networks:
      - network

networks:
  network:
    name: network
    driver: bridge
Dockerfile.dev
ARG NODE_IMAGE=node:22-slim

FROM ${NODE_IMAGE} AS base

RUN apt-get update && apt-get install -y procps

RUN npm install -g pnpm@10.13.1

FROM base AS development
WORKDIR /app

COPY package*.json pnpm-lock.yaml ./

RUN pnpm install
Originally created by @kylegillen on GitHub (Sep 3, 2025). Original GitHub issue: https://github.com/axllent/mailpit/issues/562 Hi. Awesome product! Thanks for making it 😊 When running the example docker command in the terminal, it simply keeps restarting and seemingly `exiting with code 0`: ```bash docker run -d \ --restart unless-stopped \ --name=mailpit \ -p 8025:8025 \ -p 1025:1025 \ axllent/mailpit ``` I've verified that there's nothing running on the same ports: `lsof -i tcp:8025` I've gone hunting around github repos seeing if anyone has done anything different, but to no avail. I'm not sure if there's a command that needs to be run to keep the service alive? Adding `tty: true` to the service seems to keep it running, but doesn't make the GUI available at http://localhost:8025 I'm running macOSX 15.6.1 and using Docker desktop 4.45.0 I've installed the app via homebrew, and the GUI loads as expected. Here's my full Docker related code for completeness (and just to confirm, I've also tried accessing the GUI via the port `DOCKER_MAIL_CLIENT_PORT` represents to no avail): ##### docker-compose.dev.yml ```yaml services: server: build: context: . dockerfile: Dockerfile.dev volumes: - /app/node_modules - .:/app depends_on: - database - valkey - mail command: > sh -c "pnpm start:dev" database: image: postgres:latest container_name: postgres restart: unless-stopped environment: POSTGRES_USER: '${DATABASE_USERNAME}' POSTGRES_PASSWORD: '${DATABASE_PASSWORD}' POSTGRES_DB: '${DATABASE_NAME}' TZ: 'UTC' ports: - ${DOCKER_DATABASE_PORT}:5432 volumes: - ./.docker/postgres_data:/var/lib/postgresql/data networks: - network mail: image: axllent/mailpit:latest container_name: mail restart: unless-stopped volumes: - ./.docker/mailpit_data:/data ports: - ${DOCKER_MAIL_PORT}:1025 - ${DOCKER_MAIL_CLIENT_PORT}:8025 networks: - network ``` ##### docker-compose.yml ```yaml services: server: container_name: server image: server:latest restart: unless-stopped env_file: - .env.local environment: DATABASE_HOST: '${DOCKER_DATABASE_HOST}' VALKEY_HOST: '${DOCKER_VALKEY_HOST}' ports: - ${APP_PORT}:${APP_PORT} networks: - network depends_on: - valkey valkey: image: valkey/valkey:latest container_name: valkey restart: unless-stopped ports: - ${DOCKER_VALKEY_PORT}:6379 environment: VALKEY_PASSWORD: '${VALKEY_PASSWORD}' VALKEY_IO_THREADS: '${VALKEY_IO_THREADS}' volumes: - ./.docker/valkey_data:/data healthcheck: test: '[ $$(valkey-cli --pass "${VALKEY_PASSWORD}" ping) = ''PONG'' ]' start_period: 5s timeout: 3s interval: 1s retries: 5 command: - sh - -c # this is to evaluate the $VALKEY_PASSWORD from the env - valkey-server --appendonly yes --requirepass $$VALKEY_PASSWORD --io-threads $$VALKEY_IO_THREADS --save "" ## $$ because of docker-compose networks: - network networks: network: name: network driver: bridge ``` ##### Dockerfile.dev ```dockerfile ARG NODE_IMAGE=node:22-slim FROM ${NODE_IMAGE} AS base RUN apt-get update && apt-get install -y procps RUN npm install -g pnpm@10.13.1 FROM base AS development WORKDIR /app COPY package*.json pnpm-lock.yaml ./ RUN pnpm install ```
kerem closed this issue 2026-03-15 14:05:30 +03:00
Author
Owner

@axllent commented on GitHub (Sep 3, 2025):

Hi @kylegillen. Sorry to hear about your issues. What does the docker log say, as I'm sure Mailpit will log errors if it is unsable to start properly or is exiting prematurely: docker compose logs mail (I think)?

<!-- gh-comment-id:3247485905 --> @axllent commented on GitHub (Sep 3, 2025): Hi @kylegillen. Sorry to hear about your issues. What does the docker log say, as I'm sure Mailpit will log errors if it is unsable to start properly or is exiting prematurely: `docker compose logs mail` (I think)?
Author
Owner

@kylegillen commented on GitHub (Sep 3, 2025):

Thanks so much for the prompt response @axllent 😊

I wish I had more to go on, but when I run:

docker compose --env-file .env.local --env-file .env.docker -f docker-compose.yml -f docker-compose.dev.yml logs --tail 50 --follow --timestamps mail

The only thing that gets logged is:

mail exited with code 0

In Docker Desktop the mail container simply just keeps restarting.

If I add tty: true, the container at least stays open and logs:

Welcome to Node.js v22.19.0.

Type ".help" for more information.
<!-- gh-comment-id:3247523782 --> @kylegillen commented on GitHub (Sep 3, 2025): Thanks so much for the prompt response @axllent 😊 I wish I had more to go on, but when I run: `docker compose --env-file .env.local --env-file .env.docker -f docker-compose.yml -f docker-compose.dev.yml logs --tail 50 --follow --timestamps mail` The only thing that gets logged is: `mail exited with code 0` In Docker Desktop the mail container simply just keeps restarting. If I add `tty: true`, the container at least stays open and logs: ```console Welcome to Node.js v22.19.0. Type ".help" for more information. ```
Author
Owner

@axllent commented on GitHub (Sep 3, 2025):

No problem. I'm afraid I don't have anything to go on here, except that I strongly suspect this has absolutely nothing to do with Mailpit, but rather your application in general. Mailpit goes not use node, so that Welcome to Node.js v22.19.0... message is not even coming from Mailpit container but likely your "server" container. My guess is that Mailpit is being automatically closed/exited when your "server" container exists (as it's being simply added here as a service dependency).

Sorry, I'm not much help here.

<!-- gh-comment-id:3247538902 --> @axllent commented on GitHub (Sep 3, 2025): No problem. I'm afraid I don't have anything to go on here, except that I strongly suspect this has absolutely nothing to do with Mailpit, but rather your application in general. Mailpit goes not use node, so that `Welcome to Node.js v22.19.0...` message is not even coming from Mailpit container but likely your "server" container. My guess is that Mailpit is being automatically closed/exited when your "server" container exists (as it's being simply added here as a service dependency). Sorry, I'm not much help here.
Author
Owner

@kylegillen commented on GitHub (Sep 3, 2025):

Turns out in my case it's related to adding a network to the mail service:

networks:
    - network

Does that help at all? Should a network be impacting the service this way?

<!-- gh-comment-id:3247639053 --> @kylegillen commented on GitHub (Sep 3, 2025): Turns out in my case it's related to adding a network to the mail service: ``` networks: - network ``` Does that help at all? Should a network be impacting the service this way?
Author
Owner

@kylegillen commented on GitHub (Sep 3, 2025):

Well, after starting it without the network setting, and adding it back seems to have resolved the issue 🤷‍♂️
Sorry for wasting your time, but thank you so much for the help!

<!-- gh-comment-id:3247657012 --> @kylegillen commented on GitHub (Sep 3, 2025): Well, after starting it without the network setting, and adding it back seems to have resolved the issue 🤷‍♂️ Sorry for wasting your time, but thank you so much for the help!
Author
Owner

@axllent commented on GitHub (Sep 3, 2025):

I'm pretty sure you did all the hard thinking here, so well done on solving your issue! I don't do much personally with docker compose (I tend to use docker directly), so I always feel a little helpless when things like this happen.

<!-- gh-comment-id:3247838090 --> @axllent commented on GitHub (Sep 3, 2025): I'm pretty sure you did all the hard thinking here, so well done on solving your issue! I don't do much personally with docker compose (I tend to use docker directly), so I always feel a little helpless when things like this happen.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/mailpit#362
No description provided.