Deploying with Docker
Relevant source files
The following files were used as context for generating this wiki page:Budibase offers flexible self-hosting deployment options using Docker, allowing users to run the platform on their own infrastructure. The primary methods are using Docker Compose for a multi-container setup or a single, all-in-one Docker image. These methods provide scalability and control over the Budibase environment.
This document outlines the architecture and procedures for both Docker Compose and single-image deployments, as well as the tooling available for managing Docker instances programmatically. Other deployment options include Kubernetes and Digital Ocean.
Sources: README.md:80-86, hosting/single/README.md:5-7
Deployment Methods
Budibase supports two main approaches for Docker-based deployments.
1. Docker Compose
The Docker Compose method uses a docker-compose.yaml file to orchestrate multiple services in separate containers. This is the recommended approach for most self-hosted production environments as it separates concerns and allows for individual scaling of components.
The services defined in the docker-compose.yaml file are analogous to those in the Helm chart and include the app-service, worker, proxy, MinIO for object storage, Redis, and CouchDB.
The diagram below illustrates the high-level architecture of the Docker Compose setup.
This diagram shows the relationship between the various services orchestrated by Docker Compose.
Sources: charts/budibase/README.md, packages/cli/src/hosting/utils.ts:13-24
The Budibase CLI provides utilities to manage this setup, such as downloading the docker-compose.yaml file and updating service images.
// packages/cli/src/hosting/utils.ts
export async function downloadDockerCompose() {
const filename = composeFilename()
try {
await downloadFile(COMPOSE_URL, `./${filename}`)
} catch (err) {
console.error(error(`Failed to retrieve compose file - ${err}`))
}
}
export function getServiceImage(service: string) {
const filename = composeFilename()
try {
const { services } = getServices(filename)
// ... logic to find and return service image
}
// ...
}
Sources: packages/cli/src/hosting/utils.ts:31-37, packages/cli/src/hosting/utils.ts:13-24
2. Single Image Container
As an alternative to Docker Compose, Budibase can be built into a single Docker image that contains all necessary components (Minio, CouchDB, etc.). This simplifies deployment by reducing the number of running containers to one. This method is suitable for environments where managing multiple containers is undesirable or for specific cloud services like Azure App Services.
Sources: hosting/single/README.md:5-7
Build Process
Building the single image requires Node.js, yarn, lerna, and Docker. The process involves cloning the repository, setting up the Node environment, building the project, and then building the Docker image.
The following flowchart outlines the steps to build the single image:
This diagram shows the build process for the single Docker image.
Sources: hosting/single/README.md:32-60
A specific build argument, TARGETBUILD=aas, can be used to create an image compatible with Azure App Services, which includes installing SSH and configuring data storage paths.
# Example build command for Azure App Services
docker build --build-arg TARGETARCH=amd --build-arg TARGETBUILD=aas -t budibase:latest -f ./hosting/single/Dockerfile .
Sources: hosting/single/README.md:65-69
Running the Single Image Container
Once built, the container can be run using a standard docker run command, mapping the necessary ports.
docker run -d -p 80:80 -p 443:443 --name budibase budibase:latest
If a CUSTOM_DOMAIN environment variable is set in the Dockerfile, the container will attempt to acquire a Let's Encrypt certificate for HTTPS on port 443. Otherwise, it will serve HTTP traffic on port 80.
Sources: hosting/single/README.md:73-75, hosting/single/README.md:17-23
Configuration
Docker deployments are configured primarily through environment variables. These can be set in the Dockerfile for single-image builds, a .env file for Docker Compose, or directly in the docker run command.
The Portainer template provides a clear list of the essential environment variables.
| Variable | Label | Default Value | Description |
|---|---|---|---|
MAIN_PORT | Main port | 10000 | The primary port for the proxy service. |
JWT_SECRET | JWT secret | change-me | Secret for signing JSON Web Tokens. |
MINIO_ACCESS_KEY | MinIO access key | change-me | Access key for the MinIO object storage. |
MINIO_SECRET_KEY | MinIO secret key | change-me | Secret key for the MinIO object storage. |
COUCH_DB_USER | - | budibase | Username for CouchDB. |
COUCH_DB_PASSWORD | Couch DB password | change-me | Password for the CouchDB user. |
REDIS_PASSWORD | Redis password | change-me | Password for Redis. |
INTERNAL_API_KEY | Internal API key | change-me | API key for internal service-to-service communication. |
APP_PORT | - | 4002 | Internal port for the app-service. |
WORKER_PORT | - | 4003 | Internal port for the worker-service. |
MINIO_PORT | - | 4004 | Internal port for the MinIO service. |
COUCH_DB_PORT | - | 4005 | Internal port for the CouchDB service. |
Sources: hosting/portainer/template.json:14-78
Tooling and Automation
The Budibase repository includes scripts and utilities for programmatically managing Docker containers, primarily for testing and development workflows. The packages/upgrade-tests/src/cli/docker.ts file is a key example, providing functions to automate Docker operations.
Docker Utility Functions
These functions are used in upgrade tests to create, manage, and inspect test environments.
| Function | Description |
|---|---|
generateDockerConfig() | Creates a configuration object with unique names for a container and volume. |
containerExists(name) | Checks if a container with the given name exists. |
stopContainer(name) | Stops a running container. |
removeContainer(name) | Removes a stopped container. |
createVolume(name) | Creates a new Docker volume. |
removeVolume(name) | Removes a Docker volume. |
runContainer(options) | Runs a new container with specified image, environment variables, and volume mounts. |
buildCurrentVersion(root) | Builds the project and then builds the budibase:current Docker image from the local source. |
waitForHealthy(name) | Polls a container's health status until it becomes 'healthy'. |
getContainerHealth(name) | Returns the health status of a container (e.g., 'healthy', 'starting'). |
getContainerStatus(name) | Returns the state of a container (e.g., 'running', 'exited'). |
getContainerLogs(name) | Fetches the logs from a container. |
Sources: packages/upgrade-tests/src/cli/docker.ts
Automated Test Flow
The upgrade test scripts use these Docker utilities to orchestrate a test sequence: setting up a volume, running a specific version of Budibase, waiting for it to be healthy, performing tests, and then cleaning up the resources.
The following sequence diagram illustrates this process:
This diagram shows the sequence of Docker commands executed by the test runner.
Sources: packages/upgrade-tests/src/cli/docker.ts:102-106, packages/upgrade-tests/src/cli/docker.ts:168-171, packages/upgrade-tests/src/cli/docker.ts:258-283
Summary
Deploying Budibase with Docker provides a powerful and flexible way to self-host the platform. The Docker Compose method is ideal for production, offering a modular architecture with separate, scalable services. The single-image container offers a simplified deployment for specific use cases or environments where managing multiple containers is complex. Both methods are highly configurable through environment variables. Furthermore, the internal tooling demonstrates a robust system for automating Docker-based workflows, ensuring consistency and reliability in testing and development.
Sources: README.md:80-86, hosting/single/README.md:5-7