Pausing staging and preview services outside working hours
Staging and preview services often use as much memory as production while nobody looks at them for sixteen hours a day. Pausing them outside working hours frees room for batch jobs, or lets you stay on a smaller plan.
Pick the candidates
List non-production services and their memory:
docker stats --no-stream --format '{{.Name}} {{.MemUsage}}' | grep -E 'staging|preview'
Anything that nobody uses after hours and that starts in under a minute is a candidate.
Stop and start on a schedule
A pair of cron entries on the host:
0 20 * * 1-5 docker compose -p app-staging stop
0 8 * * 1-5 docker compose -p app-staging start
Add a weekend rule if needed. stop keeps containers and volumes, so start brings them back exactly as they were.
Things that must keep running
- Databases shared with production, obviously.
- Webhooks from third parties that will retry and alert if staging is down. Point those at production test modes instead, or accept the alerts.
- Scheduled jobs inside staging that you actually rely on.
Tell the monitoring
Pause uptime checks for staging during the same hours, or they will page someone every evening.
Use the freed memory
Schedule backups, image builds or reports at night when the memory is free. That is often what lets a 4 GB server do the work of an 8 GB one.
Measure the saving
Compare the server's memory graph for a week before and after. If peak usage dropped enough, downsize at the next billing cycle.
More ideas are in this guide on how to reduce Docker costs on a VPS. I work on Peon, an open-source self-hosted deployment platform.