//Technology

Step‑by‑Step Dokku Setup with Auto‑Configured PostgreSQL & Redis

Install Dokku on Ubuntu 22.04 VPS and auto‑provision PostgreSQL & Redis sidecars for each app, delivering a Heroku‑like PaaS with isolated databases and caches.

5 min read
Step‑by‑Step Dokku Setup with Auto‑Configured PostgreSQL & Redis

Running your own platform‑as‑a‑service (PaaS) gives you full control over deployments, scaling, and data isolation. Dokku is a lightweight, Docker‑based PaaS that mimics the Heroku workflow while staying simple enough for a single‑server setup. In this guide, we walk through the complete installation of Dokku on an Ubuntu 22.04 VPS, then add automated PostgreSQL and Redis sidecars so every app gets its own isolated database and cache without manual provisioning.

1. Prerequisites and Server Preparation

Before you begin, verify that you have:

  • An Ubuntu 22.04 server with at least 2 GB RAM (4 GB is recommended for database workloads).
  • Root or sudo privileges.
  • A domain name that points to the server’s public IP (e.g., dokku.example.com).
  • Ports 80 and 443 open in the firewall.

Log in via SSH and update the system:

# apt update && apt upgrade -y
# apt install -y curl git ufw

Enable the firewall and allow the necessary ports:

# ufw allow OpenSSH
# ufw allow http
# ufw allow https
# ufw enable

2. Installing Dokku on Ubuntu 22.04

Dokku provides an official installer that takes care of Docker, the Dokku package, and required dependencies.

# curl -fsSL https://dokku.com/install/v0.31.0/bootstrap.sh | sudo bash

What the script does:

  • Installs Docker Engine from Docker’s official repository.
  • Creates a dokku user and adds it to the docker group.
  • Installs the dokku Debian package, which includes the web UI and CLI tools.

After the script completes, open a browser and navigate to http://your-domain.com. The Dokku web installer will guide you through:

  1. Adding your public SSH key (the same key you use to access the server).
  2. Setting the hostname (e.g., dokku.example.com).
  3. Enabling Let’s Encrypt for automatic HTTPS (recommended).

When the UI reports “Installation complete”, Dokku is ready to receive applications.

3. Enabling Automated PostgreSQL Sidecars

Dokku’s postgres plugin can provision a PostgreSQL container automatically whenever an app declares a DATABASE_URL environment variable.

# dokku plugin:install https://github.com/dokku/dokku-postgres.git

Configure defaults that match your workload:

# dokku postgres:set default-version 15
# dokku postgres:set default-memory 256M
# dokku postgres:set default-cpu 0.5

Enable automatic sidecar creation for all future apps:

# dokku postgres:enable --global

When you push an app that contains a DATABASE_URL variable (for example, a Rails database.yml referencing postgres://...), Dokku will:

  1. Spin up a new PostgreSQL container named postgres-APPNAME.
  2. Create a dedicated database and user for the app.
  3. Inject the correct DATABASE_URL into the app’s environment.

For an existing app, you can add the sidecar manually:

# dokku postgres:create myapp
# dokku postgres:link myapp postgres-myapp

4. Enabling Automated Redis Sidecars

Redis sidecars are managed through the redis plugin in the same way.

# dokku plugin:install https://github.com/dokku/dokku-redis.git

Set sensible defaults:

# dokku redis:set default-version 7
# dokku redis:set default-memory 128M
# dokku redis:set default-cpu 0.3

Activate the global auto‑provision flag:

# dokku redis:enable --global

When an app defines a REDIS_URL variable, Dokku will automatically:

  1. Launch a Redis container named redis-APPNAME.
  2. Expose the connection string as REDIS_URL inside the app.

To add Redis to an existing app manually:

# dokku redis:create myapp
# dokku redis:link myapp redis-myapp

5. Deploying a Sample Application with Sidecars

Below is a concise workflow for deploying a Node.js app that uses both PostgreSQL and Redis.

  1. Prepare the repository locally:
    git clone https://github.com/dokku/dokku-example-node.git
    cd dokku-example-node
    # Add a Procfile if missing
    echo "web: node index.js" > Procfile
    git add .
    git commit -m "Prepare for Dokku"
  2. Create the remote on the server (replace myapp with your desired name):
    git remote add dokku dokku@dokku.example.com:myapp
  3. Declare required environment variables so Dokku knows to spin up sidecars:
    # Trigger sidecar creation
    dokku config:set myapp DATABASE_URL=postgres://placeholder REDIS_URL=redis://placeholder

    These placeholder values only serve as triggers; Dokku replaces them with real connection strings during the build.

  4. Push the code:
    git push dokku main

    The push triggers:

    • Docker image build using the Dockerfile (or buildpacks if none).
    • Automatic creation of postgres-myapp and redis-myapp containers.
    • Injection of real DATABASE_URL and REDIS_URL into the running container.
  5. Verify the deployment:
    # dokku ps:report myapp   # shows running containers
    # dokku config myapp       # confirms real URLs are set

If everything is healthy, visiting https://myapp.example.com will display the sample app, now backed by its own PostgreSQL and Redis instances.

6. Managing and Scaling Sidecars

Sidecars are ordinary Docker containers, so you can manage them with the same commands you use for any Docker service.

  • View resource usage:
    # dokku postgres:info myapp
    # dokku redis:info myapp
  • Resize memory or CPU limits (useful when traffic grows):
    # dokku postgres:set myapp memory 512M
    # dokku redis:set myapp cpu 0.6
  • Backup PostgreSQL:
    # dokku postgres:export myapp > myapp_pg_dump.sql
  • Restore PostgreSQL:
    # cat myapp_pg_dump.sql | dokku postgres:import myapp
  • Scale the app (increase dyno count):
    # dokku ps:scale myapp web=2

    Sidecars remain singletons per app; they are not scaled automatically. For a clustered Redis, consider an external managed service.

All sidecar containers run under the dokku user, isolating them from other system processes and benefiting from Docker’s built‑in security features.

Conclusion

By following this guide, you now have a fully functional Dokku PaaS on Ubuntu 22.04, with automated PostgreSQL and Redis sidecars ready for every new application. This setup delivers a Heroku‑like developer experience while keeping costs low and giving you complete control over data residency—an ideal fit for Indian startups, SaaS teams, and hobbyists hosting on AtoZNode VPS or dedicated servers.

Remember to monitor resource consumption, back up databases regularly, and keep Docker and Dokku updated. With these practices in place, your self‑hosted PaaS will remain reliable, secure, and ready to scale as your projects grow.

dokkuubuntupostgresqlredispaascontainerizationweb‑deploymentsidecar‑services

Try it on your own server

Follow along on a Cloud VPS with full root access, or read the step-by-step knowledge base guides.

Guides: VPS for WordPress · Node.js hosting · VPS or dedicated server · Paying by UPI