Chapter 26 / 28
Production Deployment of HashiCorp Vault Using Docker
HashiCorp Vault For Beginners8 min read
Docker is everywhere—and it’s powerful, portable, and consistent. If you’re managing microservices or orchestrating infrastructure across environments, you’ve probably considered using Docker for your Vault deployment.
And yes—it’s absolutely viable for production.
In this chapter, we’ll walk through everything you need to securely run HashiCorp Vault in production using Docker:
- Why Docker for Vault
- Production-grade setup
- Static vs dynamic configuration
- Secure persistent storage
- TLS termination
- Deployment with or without a domain name
- Environment variable injection
- Memory locking and tuning
Why Docker for Vault?
Using Docker in production has some advantages:
- Simple packaging and portability
- Works on any host with Docker Engine
- Clean separation of concerns (Vault container, storage, network)
- Works with orchestration tools like Docker Compose, Kubernetes, or Nomad
But Docker does not make Vault magically production-ready.
You still need to:
- Set up secure storage
- Handle TLS correctly
- Configure auto-unsealing (if desired)
- Mount proper data volumes
- Harden access and audit
Let’s go step by step.
Step 1: Preparing the Host Machine
Install Docker on a Linux server, preferably Ubuntu LTS 24.04 or later:
sudo apt update && sudo apt install -y docker.io
sudo systemctl enable docker
Create a working directory:
mkdir -p /opt/vault-prod/config /opt/vault-prod/data /opt/vault-prod/logs
We’ll mount these into the container later:
/config: Vault configuration file(s)/data: Vault’s persistent storage/logs: Optional logging output
Step 2: Create a Production Vault Configuration File
Create /opt/vault-prod/config/vault.hcl:
ui = true
# Storage backend: Raft
storage "raft" {
path = "/vault/data"
node_id = "vault-node-1"
}
# Listener with TLS enabled
listener "tcp" {
address = "0.0.0.0:8200"
tls_cert_file = "/vault/config/certs/vault.crt"
tls_key_file = "/vault/config/certs/vault.key"
}
api_addr = "https://<<YOUR_IP_OR_FQDN_HERE>>:8200"
cluster_addr = "https://<<YOUR_IP_OR_FQDN_HERE>>:8201"
disable_mlock = false
# Log level
log_level = "info"
disable_mlock = falseensures Vault memory is not swapped to disk. You’ll need to allowCAP_IPC_LOCKwhen starting the container.
Step 3: Vault Data Directory
Vault stores everything—secrets, leases, metadata—in the Raft storage directory (/vault/data).
Best practices:
- Mount a dedicated volume for durability
- Regularly back it up (covered in snapshot chapter)
- Ensure correct permissions (
vault:vaultor100:100)
sudo chown -R 100:100 /opt/vault-prod/data
Step 4: TLS Certificates
Vault requires TLS in production to ensure secure communication between clients and the Vault server.
You can:
- Use Let’s Encrypt (with a public domain)
- Use self-signed certificates for internal deployments or IP-based access
Create a folder to store your certs:
mkdir -p /opt/vault-prod/config/certs
Generating Self-Signed TLS Certificates
You can create a self-signed TLS certificate using OpenSSL for:
- Internal FQDN (e.g.,
vault.internal.domain) - Static IP address (e.g.,
192.168.1.10)
Create a file named vault.cnf:
[req]
default_bits = 2048
prompt = no
default_md = sha256
distinguished_name = dn
req_extensions = req_ext
x509_extensions = v3_ca
[dn]
C = US
ST = CA
L = San Francisco
O = Vault Self-Signed
OU = Vault Dev
CN = vault.internal.domain
[req_ext]
subjectAltName = @alt_names
[v3_ca]
subjectAltName = @alt_names
basicConstraints = critical,CA:TRUE
keyUsage = critical, digitalSignature, keyEncipherment
extendedKeyUsage = serverAuth
[alt_names]
DNS.1 = vault.internal.domain
IP.1 = 192.168.1.10
Now generate the key and certificate:
openssl req -x509 -nodes -newkey rsa:2048 \
-keyout /opt/vault-prod/config/certs/vault.key \
-out /opt/vault-prod/config/certs/vault.crt \
-days 365 \
-config vault.cnf
This command:
- Generates a 2048-bit RSA private key
- Issues a self-signed certificate valid for 1 year
- Supports both the DNS name
vault.internal.domainand IP192.168.1.10
Replace the CN and SANs (
alt_names) with values matching your deployment.
Working with IP vs Domain Name
| Scenario | api_addr | TLS Cert CN | Use Case |
|---|---|---|---|
| IP-based setup | https://192.168.1.10:8200 | CN = IP + SAN | Internal, dev, no DNS |
| Domain-based setup | https://vault.internal.domain:8200 | CN = FQDN | Internal with DNS or hosts file |
Make sure:
- The
CNor SAN matches theapi_addr - Vault clients connect using the same address configured in
api_addr
Step 5: Start Vault with Docker
Here’s the command:
docker run -d --name vault \
--cap-add=IPC_LOCK \
-p 8200:8200 \
-p 8201:8201 \
-v /opt/vault-prod/config:/vault/config \
-v /opt/vault-prod/data:/vault/data \
-v /opt/vault-prod/config/certs:/vault/config/certs \
-e VAULT_ADDR='https://0.0.0.0:8200' \
--restart=always \
hashicorp/vault:latest server
--cap-add=IPC_LOCKenables memory locking to prevent secrets from being swapped to disk.
Step 6: Initialize and Unseal
Once running, use a separate terminal to exec into the Vault container:
docker exec -it vault vault operator init
You’ll get:
- 5 unseal keys
- 1 root token
Save these securely.
Then unseal Vault:
docker exec -it vault vault operator unseal <unseal-key>
Repeat 3 times.
Final Validation
If everything went well, visiting:
https://<<YOUR_IP_OR_FQDN_HERE>>:8200
Should show you the Vault UI.
Security Best Practices
- Never run Vault without TLS
- Remove the root token after bootstrap
- Enforce ACL policies and AppRoles
- Use audit devices (see audit devices chapter)
- Snapshot regularly and secure backups
- Mount data volumes with
noexec,nosuid
Recap
Running Vault in production with Docker gives you containerized control, fast iteration, and repeatability—but it’s still a production-grade security platform.
In this chapter, you learned how to:
- Prepare a secure Vault deployment using Docker
- Configure persistent Raft storage
- Secure your deployment with TLS
- Understand
mlock, data volumes, and IPC - Handle IP vs domain-based TLS configs
- Initialize, unseal, and talk to Vault