Self-Hosting with Docker
Relevant source files
The following files were used as context for generating this wiki page:
Self-hosting Twenty provides full control over your CRM data and infrastructure. The primary and officially supported method for self-hosting is using Docker and Docker Compose. This approach packages the application and its dependencies into a set of isolated containers, simplifying deployment and management. The core team maintains the Docker deployment, while community contributions provide alternative methods for Kubernetes and Podman.
This document outlines the architecture, installation process, and configuration for deploying Twenty via Docker. For developers looking to contribute or set up a local development environment, see the Local Setup documentation.
Sources: packages/twenty-docker/k8s/README.md:2-4, README.md:18, packages/twenty-docker/podman/README.md:2-4
Architecture
The Docker-based deployment of Twenty consists of four main services orchestrated by Docker Compose. These services work together to provide the full functionality of the CRM.
Sources: packages/twenty-docker/k8s/terraform/README.md:21-24, packages/twenty-docker/scripts/install.sh:130
The following diagram illustrates the container architecture:
This diagram shows the relationship between the main server container, the worker for background jobs, and the db and redis dependency containers.
Core Services
The docker-compose.yml file, which is downloaded during the installation process, defines the services required to run Twenty.
| Service | Image | Description |
|---|---|---|
server | twentycrm/twenty:<TAG> | The main NestJS backend application that serves the API and frontend. It is the primary entry point for user traffic. |
worker | twentycrm/twenty:<TAG> | A background worker process, based on the same image as the server, responsible for handling asynchronous jobs using a queue (e.g., BullMQ). |
db | twentycrm/twenty-postgres-spilo:latest | A PostgreSQL database for persistent data storage. The Terraform setup for Kubernetes uses this image. |
redis | redis/redis-stack-server:latest | A Redis instance used for caching, session management, and as a message broker for the job queue. |
Sources: packages/twenty-docker/scripts/install.sh:80, packages/twenty-docker/k8s/terraform/README.md:46-69, README.md:83
Installation
The recommended way to set up a self-hosted instance is through the install.sh script. This script automates dependency checking, configuration file setup, and initial launch of the application.
Sources: packages/twenty-docker/scripts/install.sh
Installation Flow
The installation script follows a clear sequence of steps to ensure the environment is correctly prepared before starting the application.
This flowchart details the execution path of the install.sh script, from dependency checks to starting the services.
Sources: packages/twenty-docker/scripts/install.sh:3-167
Key Installation Steps
- Dependency Check: The script first verifies that
docker,docker compose(v2+), andcurlare installed and that the Docker daemon is running.
Sources: packages/twenty-docker/scripts/install.sh:3-31 - Version Selection: It determines the latest version tag from Docker Hub and the corresponding GitHub branch to download the correct configuration files.
Sources: packages/twenty-docker/scripts/install.sh:44-45 - Directory Setup: It prompts the user for a directory name, creates it, and navigates into it.
Sources: packages/twenty-docker/scripts/install.sh:49-67 - Configuration Download: The script downloads
docker-compose.ymland.env.example(renaming it to.env).
Sources: packages/twenty-docker/scripts/install.sh:71-76 - Environment Configuration:
- It replaces the
TAG=latestplaceholder in the.envfile with the specific version determined earlier. - It generates secure, random values for
APP_SECRETandPG_DATABASE_PASSWORDand appends them to the.envfile.
Sources: packages/twenty-docker/scripts/install.sh:79-91
- It replaces the
- Port Configuration: It checks if the default port
3000is in use. If so, it prompts the user for a new port and updates bothdocker-compose.ymland theSERVER_URLin.env.
Sources: packages/twenty-docker/scripts/install.sh:96-114 - Service Startup: The script asks for confirmation to start the project. If confirmed, it runs
docker compose up -dand tails theserverlogs until the container's health check passes.
Sources: packages/twenty-docker/scripts/install.sh:117-136
Configuration
Configuration is managed through an .env file located in the project root. This file is created from .env.example during the installation process.
Sources: packages/twenty-docker/scripts/install.sh:75-76
Environment Variables
The following table lists key environment variables that are configured by the install.sh script.
| Variable | Description | Default / Example | Source |
|---|---|---|---|
TAG | The Docker image tag for the twenty server and worker. | Set to the latest release version. | install.sh:82-87 |
SERVER_URL | The public-facing URL of the Twenty instance. | http://localhost:3000 | install.sh:107-112 |
APP_SECRET | A randomly generated secret for application security. | Generated via openssl rand -base64 32. | install.sh:90 |
PG_DATABASE_PASSWORD | A randomly generated password for the PostgreSQL database. | Generated via openssl rand -hex 32. | install.sh:93 |
Sources: packages/twenty-docker/scripts/install.sh:75-94
The following snippet from install.sh shows how secrets are generated and appended to the .env file:
# packages/twenty-docker/scripts/install.sh:89-93
echo "# === Randomly generated secret ===" >> .env
echo "APP_SECRET=$(openssl rand -base64 32)" >> .env
echo "" >> .env
echo "PG_DATABASE_PASSWORD=$(openssl rand -hex 32)" >> .env
Alternative Deployments
While Docker Compose is the officially supported deployment method, the community provides configurations for other container orchestration platforms. These are not maintained by the Twenty core team.
Sources: packages/twenty-docker/k8s/README.md:2-4, packages/twenty-docker/podman/README.md:2-4
Kubernetes
Manifests and Terraform files are available for deploying Twenty on a Kubernetes cluster. The setup involves creating a namespace, secrets, and deployments for the server, worker, database, and Redis.
Sources: packages/twenty-docker/k8s/README.md:6-9, packages/twenty-docker/k8s/terraform/README.md:19-35
Podman
A podman-compose.yml file is provided for users who prefer Podman. The setup is similar to Docker Compose, requiring an .env file for configuration and using podman-compose up -d to start the services.
Sources: packages/twenty-docker/podman/README.md:9-11
Summary
Self-hosting Twenty with Docker provides a robust, isolated, and maintainable environment. The provided install.sh script streamlines the entire setup process, from configuration to launch, making it the recommended path for most users. The containerized architecture, defined in docker-compose.yml, ensures that all dependencies are managed correctly, offering a reliable and scalable foundation for your CRM instance.
Sources: README.md:18, packages/twenty-docker/scripts/install.sh