StackCrafted

Self-Hosting & Docker Tutorials.

View on GitHub

Vaultwarden Docker Deployment Guide

Deploy Vaultwarden securely using Docker with persistent storage and prepare it for production use behind a reverse proxy.

Vaultwarden is a lightweight, self-hosted Bitwarden-compatible password manager.

This guide follows production best practices and integrates cleanly into a reverse proxy architecture.


πŸ“¦ What This Deploys

Vaultwarden will run at:

http://127.0.0.1:8081

This is intentional and secure.


πŸ“ Folder Structure

Deployment path:

/opt/docker/vaultwarden/
β”œβ”€β”€ docker-compose.yml
β”œβ”€β”€ .env
└── data/

Create the directory:

mkdir -p /opt/docker/vaultwarden
cd /opt/docker/vaultwarden

🌐 Create the Reverse Proxy Network

This setup expects an external Docker network called web-net (shared with your reverse proxy stack).

Create it once:

docker network create web-net

If it already exists, Docker will tell you.


βš™οΈ Create docker-compose.yml

Create the file:

nano docker-compose.yml

Paste:

services:
  vaultwarden:
    image: vaultwarden/server:latest
    container_name: vaultwarden
    restart: unless-stopped
    ports:
      - "127.0.0.1:8081:80"
    volumes:
      - ./data:/data
    environment:
      - ADMIN_TOKEN=${ADMIN_TOKEN}
      - DOMAIN=${DOMAIN}
    networks:
      - web-net

networks:
  web-net:
    external: true

Save and exit.


βš™οΈ Create .env file

Create:

nano .env

Paste (update the domain):

# Public URL you will use via your reverse proxy (HTTPS recommended)
DOMAIN=https://vault.example.com

# Replace with your Argon2 hash (see next section)
ADMIN_TOKEN=replace_with_argon2_hash

Save and exit.


πŸ” Secure Admin Token (Argon2)

To securely enable the admin panel (/admin), generate a hashed token using Argon2.

  1. Ensure Argon2 is installed:
sudo apt install argon2
  1. Run the following command:
echo -n "YourStrongPassword" | argon2 "$(openssl rand -base64 32)" -e -id -k 65540 -t 3 -p 4 | sed 's#\$#\$\$#g'
  1. Copy the entire output (it will start with $$argon2id...).

  2. Paste it as the value for ADMIN_TOKEN in your .env file:

ADMIN_TOKEN=$$argon2id$$v=19$$m=65540,t=3,p=4...

▢️ Start Vaultwarden

Run:

docker compose up -d

Verify container is running:

docker ps

Expected output includes:

vaultwarden

🌐 Verify Local Access

Test locally on the server:

curl -sI http://127.0.0.1:8081 | head -n 5

Expected:

HTTP/1.1 200 OK
server: Rocket

Vaultwarden is now running.


πŸ” Access via SSH Tunnel (Optional)

From your local machine:

ssh -L 8081:127.0.0.1:8081 user@your-server-ip

If your server uses a custom SSH port (example: 1234):

ssh -p 1234 -L 8081:127.0.0.1:8081 user@your-server-ip

Then open:

http://localhost:8081

πŸ”’ Production Setup: Reverse Proxy Required

Vaultwarden is intentionally bound to:

127.0.0.1:8081

This prevents direct internet exposure.

For production use, Vaultwarden must be placed behind a reverse proxy.

Supported reverse proxies include:

Architecture overview:

Internet
   ↓
Reverse Proxy (HTTPS :443)
   ↓
Vaultwarden (127.0.0.1:8081)

The reverse proxy provides:


πŸ”§ Reverse Proxy Integration Example (Nginx)

If you already have a reverse proxy, configure it to forward to:

http://127.0.0.1:80

Example Nginx location block:

location / {
    proxy_pass http://127.0.0.1:80;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
}

πŸŽ₯ Reverse Proxy Setup (Next Tutorial)

The next StackCrafted tutorial will cover:

This reverse proxy setup will serve as the foundation for all future deployments.


πŸ’Ύ Persistent Storage

Vaultwarden data is stored in:

    /opt/docker/vaultwarden/data

Backup this directory regularly.


πŸ”„ Updating Vaultwarden

To update:

cd /opt/docker/vaultwarden
docker compose pull
docker compose up -d

πŸ›‘ Stop Vaultwarden

To stop:

docker compose down

βœ… Deployment Complete

You now have a secure, production-ready Vaultwarden deployment using Docker.

Next recommended steps:


StackCrafted tutorials focus on clean, production-ready deployments using Docker and open-source tools.