HashiCorp Vault
Secrets management and data protection platform.
Overview
HashiCorp Vault is an industry-standard secrets management and data protection platform that secures, stores, and tightly controls access to tokens, passwords, certificates, API keys, and other sensitive data. Originally developed by HashiCorp in 2015, Vault addresses the critical security challenge of managing secrets in modern distributed applications by providing centralized secret storage, dynamic secret generation, and comprehensive audit logging. Unlike traditional static credential storage, Vault treats secrets as ephemeral resources with defined lifecycles, automatically rotating credentials and revoking access when no longer needed.
This deployment combines Vault with HashiCorp Consul as the storage backend, creating a highly available and resilient secrets management infrastructure. Consul serves as Vault's distributed storage layer, providing consistent data replication, health checking, and service discovery capabilities that enable Vault to maintain state across multiple instances. The integration allows Vault to leverage Consul's Raft consensus algorithm for data consistency and provides the foundation for multi-datacenter secret management deployments.
This stack is ideal for organizations implementing zero-trust security models, DevOps teams managing credentials across multiple environments, and enterprises requiring centralized certificate authority and PKI management. The Vault-Consul combination provides enterprise-grade secrets management with the flexibility to integrate with existing authentication systems like LDAP, Active Directory, AWS IAM, and Kubernetes service accounts, making it valuable for both cloud-native startups and traditional enterprises modernizing their security infrastructure.
Key Features
- Dynamic secrets generation with automatic credential rotation for databases, cloud providers, and SSH access
- Encryption-as-a-Service providing application-layer encryption without requiring cryptographic expertise
- Policy-based access control with fine-grained permissions using HashiCorp Configuration Language (HCL)
- Multiple authentication methods including LDAP, AWS IAM, GitHub, Kubernetes, and multi-factor authentication
- Comprehensive audit logging with detailed access trails for compliance and security monitoring
- PKI secrets engine for certificate authority operations and automated certificate lifecycle management
- Consul integration providing distributed storage backend with automatic failover and data replication
- Secret leasing and renewal system with automatic revocation of expired credentials
Common Use Cases
- 1Database credential rotation for applications accessing PostgreSQL, MySQL, MongoDB, and other databases
- 2PKI certificate management for internal services, microservices TLS, and client certificate authentication
- 3Cloud provider credential management for AWS, Azure, and GCP with time-limited access tokens
- 4SSH certificate authority for secure server access without managing individual SSH keys
- 5Application secret injection for containerized workloads and Kubernetes deployments
- 6Transit encryption for encrypting application data at rest and in transit without managing keys
- 7Compliance environments requiring detailed audit trails and centralized secret governance
Prerequisites
- Minimum 512MB RAM available (256MB for Vault + 256MB for Consul)
- Ports 8200 (Vault API/UI) and 8500 (Consul UI) available and not in use
- Basic understanding of HashiCorp Configuration Language (HCL) for Vault policies
- Familiarity with public key infrastructure (PKI) concepts for certificate management
- Network access planning for integration with authentication backends like LDAP or cloud IAM
- Understanding of your organization's secret management requirements and compliance needs
For development & testing. Review security settings, change default credentials, and test thoroughly before production use. See Terms
docker-compose.yml
docker-compose.yml
1services: 2 vault: 3 image: hashicorp/vault:latest4 container_name: vault5 cap_add: 6 - IPC_LOCK7 environment: 8 - VAULT_ADDR=http://0.0.0.0:82009 - VAULT_API_ADDR=http://0.0.0.0:820010 - VAULT_DEV_ROOT_TOKEN_ID=${VAULT_DEV_TOKEN}11 volumes: 12 - vault-data:/vault/data13 - vault-logs:/vault/logs14 - ./vault-config.hcl:/vault/config/vault.hcl:ro15 ports: 16 - "8200:8200"17 command: server18 depends_on: 19 - consul20 networks: 21 - vault-network22 restart: unless-stopped2324 consul: 25 image: hashicorp/consul:latest26 container_name: consul27 command: agent -server -bootstrap-expect=1 -ui -client=0.0.0.028 environment: 29 - CONSUL_BIND_INTERFACE=eth030 volumes: 31 - consul-data:/consul/data32 ports: 33 - "8500:8500"34 - "8600:8600/udp"35 networks: 36 - vault-network37 restart: unless-stopped3839volumes: 40 vault-data: 41 vault-logs: 42 consul-data: 4344networks: 45 vault-network: 46 driver: bridge.env Template
.env
1# HashiCorp Vault2VAULT_DEV_TOKEN=myroot34# For production, use proper initialization:5# vault operator init6# vault operator unsealUsage Notes
- 1Vault UI at http://localhost:8200
- 2Consul UI at http://localhost:8500
- 3Initialize: vault operator init
- 4Unseal with 3 of 5 keys
- 5Store secrets, certificates, credentials
Individual Services(2 services)
Copy individual services to mix and match with your existing compose files.
vault
vault:
image: hashicorp/vault:latest
container_name: vault
cap_add:
- IPC_LOCK
environment:
- VAULT_ADDR=http://0.0.0.0:8200
- VAULT_API_ADDR=http://0.0.0.0:8200
- VAULT_DEV_ROOT_TOKEN_ID=${VAULT_DEV_TOKEN}
volumes:
- vault-data:/vault/data
- vault-logs:/vault/logs
- ./vault-config.hcl:/vault/config/vault.hcl:ro
ports:
- "8200:8200"
command: server
depends_on:
- consul
networks:
- vault-network
restart: unless-stopped
consul
consul:
image: hashicorp/consul:latest
container_name: consul
command: agent -server -bootstrap-expect=1 -ui -client=0.0.0.0
environment:
- CONSUL_BIND_INTERFACE=eth0
volumes:
- consul-data:/consul/data
ports:
- "8500:8500"
- 8600:8600/udp
networks:
- vault-network
restart: unless-stopped
Quick Start
terminal
1# 1. Create the compose file2cat > docker-compose.yml << 'EOF'3services:4 vault:5 image: hashicorp/vault:latest6 container_name: vault7 cap_add:8 - IPC_LOCK9 environment:10 - VAULT_ADDR=http://0.0.0.0:820011 - VAULT_API_ADDR=http://0.0.0.0:820012 - VAULT_DEV_ROOT_TOKEN_ID=${VAULT_DEV_TOKEN}13 volumes:14 - vault-data:/vault/data15 - vault-logs:/vault/logs16 - ./vault-config.hcl:/vault/config/vault.hcl:ro17 ports:18 - "8200:8200"19 command: server20 depends_on:21 - consul22 networks:23 - vault-network24 restart: unless-stopped2526 consul:27 image: hashicorp/consul:latest28 container_name: consul29 command: agent -server -bootstrap-expect=1 -ui -client=0.0.0.030 environment:31 - CONSUL_BIND_INTERFACE=eth032 volumes:33 - consul-data:/consul/data34 ports:35 - "8500:8500"36 - "8600:8600/udp"37 networks:38 - vault-network39 restart: unless-stopped4041volumes:42 vault-data:43 vault-logs:44 consul-data:4546networks:47 vault-network:48 driver: bridge49EOF5051# 2. Create the .env file52cat > .env << 'EOF'53# HashiCorp Vault54VAULT_DEV_TOKEN=myroot5556# For production, use proper initialization:57# vault operator init58# vault operator unseal59EOF6061# 3. Start the services62docker compose up -d6364# 4. View logs65docker compose logs -fOne-Liner
Run this command to download and set up the recipe in one step:
terminal
1curl -fsSL https://docker.recipes/api/recipes/hashicorp-vault/run | bashTroubleshooting
- Vault sealed state after restart: Run 'vault operator unseal' with threshold number of unseal keys from initialization
- Consul connection refused errors: Verify Consul container is running and accessible on port 8500 before starting Vault
- Permission denied accessing secrets: Check Vault policies attached to your authentication token using 'vault token lookup'
- Vault initialization hanging: Ensure IPC_LOCK capability is granted to prevent memory swapping issues
- High availability setup failing: Verify Consul cluster has odd number of nodes and proper network connectivity between instances
- Authentication backend integration failing: Confirm network connectivity to LDAP/AD servers and verify service account permissions
Community Notes
Loading...
Loading notes...
Download Recipe Kit
Get all files in a ready-to-deploy package
Includes docker-compose.yml, .env template, README, and license
Ad Space
Shortcuts: C CopyF FavoriteD Download