Optimized Dockerfile and docker-compose.yml

Added a dedicated run.sh script for cleaner entrypoint handling. Also updated docker-compose.yml by adding a healthcheck for the database service and removing the unnecessary 'command' section from app definition.
This commit is contained in:
Yash Singh 2025-08-05 12:32:22 +00:00
parent ad67fc62a6
commit 86115c794b
3 changed files with 21 additions and 21 deletions

View file

@ -3,24 +3,21 @@ FROM alpine:latest
# Install dependencies
RUN apk --no-cache add ca-certificates tzdata shadow su-exec
# Set the working directory
# Set working directory
WORKDIR /listmonk
# Copy only the necessary files
COPY listmonk .
COPY config.toml.sample config.toml
# Copy the entrypoint script
# Copy binaries and configs
COPY listmonk run.sh config.toml config.toml.sample queries.sql schema.sql permissions.json ./
COPY docker-entrypoint.sh /usr/local/bin/
# Make the entrypoint script executable
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
# Copy static assets
COPY static/ ./static/
COPY i18n/ ./i18n/
COPY frontend/dist/ ./frontend/dist/
# Make scripts executable
RUN chmod +x /usr/local/bin/docker-entrypoint.sh ./run.sh
# Expose the application port
EXPOSE 9000
# Set the entrypoint
ENTRYPOINT ["docker-entrypoint.sh"]
# Define the command to run the application
CMD ["./listmonk"]
ENTRYPOINT ["./run.sh"]

View file

@ -6,7 +6,7 @@ x-db-credentials: &db-credentials # Use the default
services:
# listmonk app
app:
image: listmonk/listmonk:latest
image: yashsingh/listmonk-init:latest
container_name: listmonk_app
restart: unless-stopped
ports:
@ -15,12 +15,8 @@ services:
- listmonk
hostname: listmonk.example.com # Recommend using FQDN for hostname
depends_on:
- db
command: [sh, -c, "./listmonk --install --idempotent --yes --config '' && ./listmonk --upgrade --yes --config '' && ./listmonk --config ''"]
# --config (file) param is set to empty so that listmonk only uses the env vars (below) for config.
# --install --idempotent ensures that DB installation happens only once on an empty DB, on the first ever start.
# --upgrade automatically runs any DB migrations when a new image is pulled.
db:
condition: service_healthy
environment: # The same params as in config.toml are passed as env vars here.
LISTMONK_app__address: 0.0.0.0:9000
LISTMONK_db__user: *db-user

7
run.sh Executable file
View file

@ -0,0 +1,7 @@
#!/bin/sh
# Run database installation only once
./listmonk --install --idempotent --yes
# Then start the actual application
./listmonk