
Dokku is an open-source Platform-as-a-Service (PaaS) that transforms a Linux server into a lightweight application deployment platform. Built on Docker, it enables Git-based deployments similar to Heroku while maintaining full control over your infrastructure. Dokku supports multiple programming languages, automatic SSL certificate provisioning, environment variable management, and zero-downtime deployments through a simple command-line interface.
This article explains how to deploy Dokku on a Linux-based server using Docker Compose, configure SSH-based Git deployments, manage application environment variables, and enable automatic HTTPS with Let's Encrypt certificates through Traefik integration.
Before you begin, you need to:
dokku.example.com).Dokku requires a project directory for Docker Compose files and a data directory for persistent application storage. The .env file defines the hostname and version variables that Docker Compose injects into the container at runtime.
Create the project directory structure.
The ~/dokku directory stores your Docker Compose project files (docker-compose.yml, .env), and ~/dokku/data holds Dokku's persistent application data that mounts into the container.
Navigate to the project directory.
Create a .env file.
Add the following environment variables:
Replace dokku.example.com with your registered domain. The next section uses these values to create a Docker Compose manifest and start Dokku as a containerized service on your server.
Save and close the file.
Docker Compose manages Dokku as a containerized service with persistent storage volumes. The configuration exposes port 3022 for SSH-based Git deployments and mounts the Docker socket to enable Dokku to create and manage application containers on the host.
Add your user account to the Docker user group. This allows you to run Docker commands without sudo.
Apply the new group membership.
Create and edit a Docker Compose manifest file.
Add the following contents:
The configuration does the following:
image: Pins the Dokku container image version from your .env file.ports: Publishes the Dokku SSH port on the host, mapping host port 3022 to container port 22 for Git deployments."./data:/mnt/dokku": Persists Dokku state (apps, config, plugins, certificates) in the ~/dokku/data directory."/var/run/docker.sock:/var/run/docker.sock": Bind-mounts the host Docker socket into the container, allowing Dokku to create and manage application containers directly on the host Docker daemon.restart: Ensures Dokku starts automatically after reboots.Save and close the file.
Start the services.
Verify the service's status.
Verify that the Dokku container is in the running state and the mapped ports are correct.
For more information on managing a Docker Compose stack, see the How To Use Docker Compose article.
Dokku uses SSH for all application management tasks, including creating apps, deploying code via Git, and managing domains and configuration. SSH key authentication eliminates the need for password-based login and provides secure communication between your local machine and the Dokku server. The key must be registered with Dokku before remote operations can proceed.
On your local machine (the machine from which you SSH into your server), generate an SSH key.
ssh-keygen: Generates an SSH key pair (private + public key) for secure, passwordless authentication.-t ed25519: Uses the Ed25519 algorithm (modern, fast, secure).-f ~/.ssh/id_ed25519: Saves the private key as ~/.ssh/id_ed25519 and the public key as ~/.ssh/id_ed25519.pub.-C "dokku": Adds a label to the public key so you can identify its purpose later (in this case, it labels the key as Dokku).Display your public key and copy the output to your clipboard.
On the server (the instance where Dokku runs), add your public key to Dokku. Replace YOUR_SSH_KEY with your own key.
docker compose exec -T dokku: Runs a command inside the running Dokku container that the Docker Compose file defines as the Dokku service. -T disables pseudo-TTY allocation, which piping input into the container requires.dokku ssh-keys:add admin: Registers the incoming public key in Dokku under the name admin, allowing SSH/Git deployments with the matching private key.Verify the SSH key registration.
The output lists your registered SSH key with the name admin. Dokku now recognizes your SSH key, allowing secure access and deployments.
The SSH config file creates a host alias that simplifies Dokku commands by storing the server IP, username, port, and identity file path. The alias enables short command syntax like ssh dokku-server instead of full connection strings.
Open ~/.ssh/config on your local machine.
Add the following content:
Replace YOUR_SERVER_IP with your server's public IP address.
Save and close the file.
Test the connection from your local machine.
The Dokku command list confirms SSH access is configured correctly.
Verify the Dokku version.
The output displays the installed Dokku version.
Dokku receives code through Git push operations, automatically detects the application type using buildpacks, builds the application, and exposes it through the configured domain. The deployment process requires creating an application in Dokku, adding a Git remote, and pushing code to trigger the build.
Create an application from your local machine.
This creates a new Dokku application named ruby-getting-started and configures its virtual host settings.
Verify that the application is created.
The output lists all deployed applications, including ruby-getting-started.
Clone the sample application locally.
Navigate to the application directory.
Add the Dokku Git remote.
This command adds a Git remote named dokku that points to your Dokku server and application.
Deploy the application to Dokku.
Dokku receives the code, builds the application, and deploys it. The output displays the application URL where it's accessible.
Environment variables store sensitive configuration values such as API keys, database credentials, and authentication tokens outside your application code. This approach prevents committing secrets to version control and allows different configurations across development, staging, and production environments.
Set a single environment variable for your application.
Dokku automatically restarts the application to apply the new configuration.
Set multiple environment variables in a single command.
View all configured environment variables.
The output displays all environment variables currently set for the application.
Your application code accesses these environment variables using standard language methods: ENV["SECRET_KEY"] in Ruby, os.environ["SECRET_KEY"] in Python, or process.env.SECRET_KEY in Node.js.
Remove an environment variable when you no longer need it.
This removes the variable and restarts the application.
Verify that the variable is removed.
The output confirms the variable no longer appears in the configuration.
Dokku includes Traefik integration that automatically provisions and renews Let's Encrypt certificates for deployed applications. The Traefik proxy replaces the default nginx proxy and handles TLS termination, routing, and certificate management through ACME protocol.
Stop the default nginx proxy.
Set Traefik as the global default proxy for all applications.
Set the Let's Encrypt email address globally for certificate registration and expiry notifications.
Replace username@example.com with your email address.
Set the domain for your application.
Replace dokku.example.com with your registered domain.
Start the Traefik proxy.
Rebuild the application to inject Traefik labels into the app containers.
Open your web browser and navigate to your application domain using HTTPS.
Replace dokku.example.com with your registered domain.
The browser displays a padlock icon, confirming a secure TLS connection. Traefik successfully obtained and installed the Let's Encrypt certificate for the domain.
You have successfully deployed Dokku as a containerized Platform-as-a-Service using Docker Compose. The setup provides Git-based deployments, SSH authentication, environment variable management, and automatic SSL/TLS certificates through Traefik. For more information, visit the official Dokku documentation.
0 Comments
Be the first to comment and share your perspective with the community.