Migrate from Heroku to Docker

Updated

Heroku has had no free dynos since 2022, and plenty of hobby apps, demos and bots were left looking for a new home. This guide moves a typical Heroku web app into a Docker image and puts it back on a public HTTPS URL. If you are still choosing a platform, start with APPISH vs Heroku.

First: does your app fit?

APPISH runs one container per slot. Your app moves over cleanly if:

If you rely on Heroku add-ons, review apps or pipelines, a full PaaS is a better fit. The honest comparison is on Why Appish.

1. Turn the Procfile into a Dockerfile

A Procfile like this:

web: node server.js
release: npm run migrate

becomes:

FROM node:22-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev
COPY . .
ENV NODE_ENV=production PORT=3000
EXPOSE 3000
CMD ["sh", "-c", "npm run migrate && node server.js"]

Two details:

Python, Ruby or Go apps follow the same pattern; see the FastAPI and Node.js guides for complete Dockerfiles.

2. Carry over config vars

Print them in shell format:

heroku config --shell -a your-app

Each variable becomes an image tag. Simple values go in env_KEY___VALUE (three underscores). Anything with :, /, @ or = — database URLs, API keys — goes in env64_KEY___VALUE with the value base64url-encoded. The docs have one-liners for the encoding.

3. Move the database

Take a backup of Heroku Postgres and download it:

heroku pg:backups:capture -a your-app
curl -o latest.dump "$(heroku pg:backups:url -a your-app)"

Create a database with a hosted Postgres provider and restore into it:

pg_restore --no-owner --no-acl -d "postgres://user:pass@host:5432/db" latest.dump

Then pass the new connection string as env64_DATABASE_URL___....

4. Push

docker buildx build --platform linux/amd64 \
  -t push.to.appi.sh/<your-push-id>/app:port_3000 \
  -t push.to.appi.sh/<your-push-id>/app:env_NODE_ENV___production \
  -t push.to.appi.sh/<your-push-id>/app:env64_DATABASE_URL___<base64url> \
  --push .

Copy your push address from the APPISH Dashboard. When the slot turns Healthy, the app answers at https://<your-slot>.appi.sh. Check it, then scale the Heroku dynos to zero.

A free slot runs for 4 hours per deployment and can be extended with one click. An app that should stay up for good needs a paid slot.

Related