
HashiCorp Vault is a centralized secrets management system that protects sensitive data using identity-based access controls. It provides a unified interface for securely handling passwords, tokens, certificates, and encryption keys across distributed systems.
This article demonstrates how to deploy a production-ready HashiCorp Vault instance on Ubuntu 24.04 using Docker Compose. It is configured with Raft Integrated Storage for high-availability data persistence and secured with HTTPS via a Traefik reverse proxy.
Before you begin:
vault.example.com, to point to your server’s public IP address.HashiCorp Vault requires persistent storage for its Raft data, audit logs, TLS certificates, and configuration files, along with environment variables that specify its domain and Let’s Encrypt email. This section covers creating the folders, the vault.hcl configuration file, and the .env file that Docker Compose uses to load domain and email values automatically.
Create folders to store Vault data, configuration, and logs.
config - Stores the vault.hcl configuration file.data - Persistent storage for the Raft backend (encrypted secrets).logs - Audit logs.letsencrypt - Traefik ACME certificates.The Vault container runs as UID 100. Change the ownership of data and logs to UID 100 to allow writing to these directories.
Navigate to the root Vault directory.
Create the Vault configuration file.
Add the following configuration:
Replace vault.example.com with your actual domain. Save and close the file.
The above configuration defines Vault's core operational parameters. Within the configuration:
ui = true: Enables Vault's web-based user interface for easier management.storage "raft" { ... }: Configures Raft as the storage backend for high-availability data persistence, with data stored in /vault/data and a unique node ID.listener "tcp" { ... }: Sets up an HTTP listener on port 8200 (TLS disabled since Traefik handles encryption).api_addr: Specifies the public HTTPS address clients use to access Vault.cluster_addr: Defines the internal address for cluster communication between Vault nodes.disable_mlock = false: Keeps memory locking enabled so Vault can prevent sensitive data from being swapped to disk. Since the container includes the IPC_LOCK capability, Vault is allowed to lock memory safely in this deployment.Create an .env file to store your email for Let's Encrypt and your domain.
Add the following content. Replace vault.example.com with your actual domain and admin@example.com with your email address.
Save and close the file.
This section covers the deployment of HashiCorp Vault using Docker Compose. The configuration includes Traefik to act as a reverse proxy. This setup offloads SSL termination to Traefik, ensuring secure HTTPS communication without requiring direct certificate management within Vault.
Add your user account to the docker user group.
Apply new group membership.
Create the Docker Compose manifest file.
Add the following contents:
Save and close the file. This Docker Compose configuration deploys HashiCorp Vault behind Traefik, which handles HTTPS termination and certificate automation. Vault runs with Raft Integrated Storage for durability and relies on Traefik for secure external access. Each service has a dedicated role within the stack:
vault service
hashicorp/vault image in server mode../config, Raft storage under ./data, and audit logs under ./logs.cap_add: IPC_LOCK to allow memory locking so Vault can prevent sensitive data from being swapped to disk (recommended for production).vault.hcl file located in the mounted config directory.https://${VAULT_DOMAIN} are forwarded to Vault over port 8200.traefik service
./letsencrypt directory.Start all services in detached mode.
Check the container status.
Both vault and traefik should show a status of Up.
For more information on managing a Docker Compose stack, see the How To Use Docker Compose article.
Vault starts in a "Sealed" state. The data is encrypted, and Vault cannot access it until you provide the unseal keys.
Run the following command in your terminal to generate the master keys. This executes the initialization tool directly inside the running container.
The output contains 5 Unseal Keys and an Initial Root Token.
Copy all the Unseal Keys and the Root Token, and store them safely. If you lose these keys, you lose access to your data permanently. There is no password reset for Vault.
Access the Vault UI by visiting https://vault.example.com.
Vault requires a "quorum" of keys to unlock. Copy Unseal Key 1 from from the output of step 1, paste it into the box, and click Unseal.
Repeat the process by entering two more Unseal Keys. Once 3 valid keys are entered, the Sign in page loads.
Enter the Initial Root token from the output of step 1 in the Token field. The Vault dashboard loads.
You have successfully deployed a secure HashiCorp Vault instance on Ubuntu 24.04. Your setup uses Raft Integrated Storage for data durability and Traefik for automatic HTTPS. For more information, refer to the Vault documentation.
0 Comments
Be the first to comment and share your perspective with the community.