Here is a pattern I see constantly with solo founders. The app runs in Docker. docker compose up works perfectly on the laptop. Then production happens: a VPS with a hand-edited Nginx config, a cron job someone copied from a gist for backups, a disk that fills up at 2 AM, or a platform bill that doubled because something scaled in a way nobody could predict.
The irony is that you already did the hard part. Packaging your app into a container is the whole point of containerized deployment: the same artifact runs the same way everywhere. What went wrong is not the container. It is everything you built around it by hand.
This guide is a practical migration plan for moving a Dockerized SaaS (app, database, and file storage) from a self-managed server or an opaque platform onto a managed stack with a price you can state before you deploy. It is sized for a Saturday.
What containerized deployment actually buys you
A container image bundles your code, runtime, system libraries, and dependencies into one versioned unit. That gives you three properties that matter during a migration:
- Portability. The image that runs on your laptop runs on any platform that runs OCI containers. You are not rewriting your app to migrate it.
- Immutability. A deploy is "run image
v42", not "SSH in andgit pull". Rollback is "run imagev41". - A clean boundary. Everything inside the image is your responsibility. Everything outside (TLS, routing, restarts, scaling, the database server, disks) can be someone else's.
That last point is the whole game. On a raw VPS, you own both sides of the boundary. On a managed platform, you only own the image and its configuration.
The goal of this migration is not "move to the cloud." It is "stop owning the things outside the container."
Step 0: inventory what your server is secretly doing
Before you move anything, write down everything the current setup does. Servers accumulate responsibilities nobody remembers. Spend 20 minutes on this list:
# On the old server
docker ps -a --format "table {{.Names}}\t{{.Image}}\t{{.Ports}}"
docker volume ls
crontab -l
sudo ls /etc/nginx/sites-enabled/
sudo systemctl list-timers
df -hFor each item, answer: what is this, and where does it go after the migration?
| Thing on the old server | Where it goes |
|---|---|
| App container | Managed app service, same image |
| Postgres container or local install | Managed database |
/var/www/uploads or a Docker volume with files | S3-compatible object storage |
| Nginx reverse proxy and TLS certs | Platform's HTTPS routing (delete) |
| Backup cron script | Managed database backups or a scheduled job (check what your provider includes) |
| Worker or queue consumer | Second service from the same image |
| Random cron jobs | Scheduled job, or a worker loop |
Anything you cannot map is a risk. Find it now, not after DNS has switched.
Step 1: make the image production-ready
An image that works locally is not always an image that works well in production. Four changes cover most of the gap.
Use a multi-stage build
Keep build tools out of the runtime image. Smaller images build and deploy faster, and have fewer vulnerabilities to patch. A FastAPI example:
# syntax=docker/dockerfile:1
FROM python:3.13-slim AS build
WORKDIR /app
RUN pip install --no-cache-dir --upgrade pip
COPY requirements.txt .
RUN pip wheel --no-cache-dir --wheel-dir /wheels -r requirements.txt
FROM python:3.13-slim
WORKDIR /app
RUN useradd --create-home --uid 10001 appuser
COPY --from=build /wheels /wheels
RUN pip install --no-cache-dir /wheels/* && rm -rf /wheels
COPY . .
USER appuser
ENV PORT=8000
EXPOSE 8000
CMD ["sh", "-c", "exec uvicorn main:app --host 0.0.0.0 --port ${PORT} --proxy-headers"]Run as a non-root user
The USER appuser line above matters. If your app is compromised, an attacker lands as an unprivileged user instead of root inside the container.
Read everything from environment variables
Grep your code for hard-coded hosts and keys:
grep -rnE "localhost|127\.0\.0\.1|sk_live|AKIA" --include="*.py" --include="*.ts" --include="*.js" .Database URLs, storage credentials, API keys, and the port must all come from the environment. This is what lets the same image run locally, in staging, and in production.
Handle shutdown signals
Platforms replace containers during every deploy. Using exec in the CMD (as above) makes your server PID 1 so it receives SIGTERM and can finish in-flight requests instead of being killed mid-response.
Build and run it locally with production-like settings before going further:
docker build -t myapp:migrate .
docker run --rm -p 8000:8000 --env-file .env.production.local myapp:migrateStep 2: move files off the local disk
If users upload avatars, PDFs, or CSVs, and those land on the server's disk or a Docker volume, they must move to object storage. Containers on a managed platform are disposable; their local filesystem is not a place to keep anything.
Code change first. Any S3 SDK works with S3-compatible storage as long as you set a custom endpoint:
import os
import boto3
s3 = boto3.client(
"s3",
endpoint_url=os.environ["S3_ENDPOINT"],
aws_access_key_id=os.environ["S3_ACCESS_KEY_ID"],
aws_secret_access_key=os.environ["S3_SECRET_ACCESS_KEY"],
)
def save_upload(file_obj, key: str) -> None:
s3.upload_fileobj(file_obj, os.environ["S3_BUCKET"], key)Then copy existing files. rclone handles this well and can resume if interrupted. Configure a remote once (rclone config, provider "S3", then "Other" or your provider, with the endpoint and keys), then:
rclone copy /var/www/uploads newstore:my-bucket/uploads --progress --transfers 16
rclone check /var/www/uploads newstore:my-bucket/uploadsRun the copy once now and once more right before cutover to catch files uploaded in between. Store object keys (not full URLs) in your database, so switching the public domain or CDN later is a config change.
Step 3: move the database
For most MVP-sized databases (under a few tens of GB), a dump and restore is the simplest and safest path.
# From anywhere that can reach both databases
pg_dump -Fc --no-owner --no-acl -d "$OLD_DATABASE_URL" -f app.dump
pg_restore --no-owner --no-acl -d "$NEW_DATABASE_URL" app.dump-Fcproduces a compressed custom-format dump thatpg_restorecan parallelize (-j 4).--no-owner --no-aclavoids errors when role names differ between old and new servers, which they almost always do on managed databases.- Use a
pg_dumpclient version equal to or newer than the old server's version.
Then verify, do not assume:
psql "$NEW_DATABASE_URL" -c "SELECT relname, n_live_tup FROM pg_stat_user_tables ORDER BY n_live_tup DESC LIMIT 10;"n_live_tup is a statistics estimate (run ANALYZE; after the restore so it is populated), so for the tables that matter most, run an exact SELECT count(*) on both sides and compare. Check that extensions you rely on (pgcrypto, pg_trgm, uuid-ossp) exist on the new server.
Do a full rehearsal on staging first. Time it. The rehearsal tells you how long your maintenance window needs to be.
Step 4: deploy the container on the new platform
This is where a managed platform earns its keep. On Granite.so the flow looks like this:
- Create the app by connecting your Git repository (every push rebuilds and redeploys) or by pointing it at the Docker image you already push to a registry.
- Create a managed PostgreSQL database and restore your dump into it (step 3).
- Create an S3-compatible storage bucket, with the built-in CDN in front of it for public assets, and copy files into it (step 2).
- Set environment variables:
DATABASE_URL,S3_ENDPOINT,S3_BUCKET, access keys, and the rest of your.env. - Add a worker service from the same image with a different start command, if you have background jobs.
- Deploy and hit the platform-provided HTTPS URL.
Notice what is missing from that list: no Nginx config, no Certbot, no firewall rules, no systemd units, no backup script you wrote yourself. Automatic scaling handles traffic spikes, which works because your containers are now stateless.
Smoke test before switching DNS
Run through your critical paths on the temporary URL:
- Sign up, log in, log out, log in again (sessions survive restarts)
- Upload a file, reload, download it (storage works)
- Trigger a background job (worker is connected)
- Trigger a webhook from Stripe's test mode or your email provider (external callbacks reach you)
- Check the logs for errors during all of the above
Step 5: cut over with minimal downtime
- A day before, lower the TTL on your DNS records to 300 seconds so the switch propagates quickly.
- Put the old app in maintenance mode or read-only mode to stop new writes.
- Take a final database dump and restore it (a fresh restore into an empty database is cleanest).
- Run the final
rclone copyfor files. - Point your domain at the new platform and wait for the certificate to be issued.
- Re-run the smoke test on the real domain.
- Keep the old server running but idle for a week, in case you need to roll back or discover a forgotten cron job.
For a small SaaS, this is typically 15–30 minutes of write downtime. Announce it to your beta users in advance; they will forgive a scheduled window far more easily than a surprise outage.
Step 6: make the bill predictable
Part of why you are migrating is money you could not predict. Before you move production, do the arithmetic you could not do on the old setup:
| Line item | Old setup | New setup |
|---|---|---|
| Compute for app and worker | VPS or usage-based platform | Included in plan and usage credits |
| Database | Self-managed, your time | Managed database |
| File storage and CDN | Local disk, no CDN | S3-compatible storage with CDN |
| Backups | Your cron script | Check what the provider includes |
| Your time on ops per week | Several hours | Close to zero |
On Granite.so, the Hobby plan is $9 per month and includes $15 of monthly usage credits, which covers a typical early-stage app, database, and bucket serving the first handful of paying users. Higher tiers exist when you outgrow it; check the pricing page for current limits so you know exactly where the next step up is before you need it.
Two habits keep costs honest on any platform:
- Set scaling limits so a traffic spike or a bot cannot quietly multiply your instance count.
- Review usage monthly for the first few months, while you learn your app's real footprint.
Honest trade-offs
Containerized deployment on a managed platform is the right default for most MVPs, but not all of them:
- You give up root access. If you need custom kernel settings, GPUs, or unusual networking, a VM or Kubernetes may still be the right tool.
- Very large databases (hundreds of GB) need a replication-based migration rather than dump and restore. Plan more than a Saturday.
- Regulated data may require specific regions or certifications. Verify them before migrating, not after.
If none of those apply, the math is simple: you already have the container. Stop maintaining the server around it.
Your migration checklist
- Inventory everything the old server does
- Multi-stage, non-root image that reads config from env and handles
SIGTERM - Uploads moved to S3-compatible storage; code uses a configurable endpoint
- Database dumped, restored, and verified on staging
- App, worker, database, and bucket running on the new platform
- Smoke test passed on the temporary URL
- DNS TTL lowered, final sync done, domain switched
- Old server kept idle for a week, then shut down
Ready to try it on your staging environment first? Create a Granite.so account, connect your repo, and run through steps 2 to 4 this afternoon. Your production cutover can wait until the rehearsal is boring.