Skip to content

Auto-Generated Password Setup

Auto-Generated Password Setup - Complete ✅

Section titled “Auto-Generated Password Setup - Complete ✅”

Date: November 18, 2025 Status: Production Ready with Automatic Password Generation

This setup automatically generates a secure random password on first startup and configures both PostgreSQL and OpenVSCode Server to use it. No manual password configuration required!

On first run, a lightweight Alpine container generates a 32-byte random password:

init-secrets:
image: alpine:latest
command: >
sh -c "
if [ ! -f /run/secrets/db_password ]; then
echo 'Generating random database password...';
openssl rand -base64 32 > /run/secrets/db_password;
echo 'Password generated successfully';
fi"

Generated password example: Dm1bWa5V6WflahNkIVpsheF9HCWBNj0GroZ3rE4PaLg=

The password is stored in a Docker volume mounted to both containers:

volumes:
secrets:
driver: local

Both containers mount this volume at /run/secrets:

  • postgres-pgvector: Reads password from /run/secrets/db_password
  • openvscode-server: Reads password from /run/secrets/db_password

PostgreSQL natively supports password files via POSTGRES_PASSWORD_FILE:

postgres:
environment:
POSTGRES_PASSWORD_FILE: /run/secrets/db_password
volumes:
- secrets:/run/secrets:ro

A custom entrypoint script reads the password and creates VS Code settings:

#!/bin/bash
PASSWORD_FILE=/run/secrets/db_password
DB_PASSWORD=$(cat "$PASSWORD_FILE")
cat > /home/.openvscode-server/data/User/settings.json << EOF
{
"workspaceRag.pgHost": "postgres-pgvector",
"workspaceRag.pgPassword": "$DB_PASSWORD",
...
}
EOF
exec /home/.openvscode-server/bin/openvscode-server ...
┌─────────────────────────────────────────────────────┐
│ Docker Compose Startup Sequence │
│ │
│ 1. init-secrets (runs once) │
│ ├─ Generates random password │
│ └─ Stores in /run/secrets/db_password │
│ │
│ 2. postgres-pgvector (waits for init-secrets) │
│ ├─ Reads /run/secrets/db_password │
│ └─ Initializes with generated password │
│ │
│ 3. openvscode-server (waits for postgres healthy) │
│ ├─ Reads /run/secrets/db_password │
│ ├─ Creates settings.json with password │
│ └─ Starts IDE │
│ │
│ Result: Both services use same random password! ✅ │
└─────────────────────────────────────────────────────┘
Terminal window
# Start services - password will be generated automatically
docker-compose up -d
# Check logs to see password generation
docker logs init-secrets
# Output: "Generating random database password..."
# "Password generated successfully"
# Access IDE
open http://localhost:3000
Terminal window
# Start services - uses existing password
docker-compose up -d
# Check logs
docker logs init-secrets
# Output: "Using existing password"
Terminal window
# View the generated password
docker exec openvscode-server cat /run/secrets/db_password
# Example output:
# Dm1bWa5V6WflahNkIVpsheF9HCWBNj0GroZ3rE4PaLg=
Terminal window
# Check OpenVSCode settings
docker exec openvscode-server cat /home/.openvscode-server/data/User/settings.json
# Should show:
# {
# "workspaceRag.pgHost": "postgres-pgvector",
# "workspaceRag.pgPassword": "Dm1bWa5V6WflahNkIVpsheF9HCWBNj0GroZ3rE4PaLg=",
# ...
# }
# Check PostgreSQL has same password
docker exec postgres-pgvector cat /run/secrets/db_password
# Should match the password in settings.json
Terminal window
# Test PostgreSQL is accessible
docker-compose exec postgres psql -U postgres -d workspace_rag -c "SELECT 1;"
# Should return:
# test
# ------
# 1
# (1 row)
  • 32-byte random password (256 bits of entropy)
  • Generated using OpenSSL’s cryptographically secure RNG
  • Base64 encoded for safe storage
  • Different password for each installation
  • No passwords in source code
  • No passwords in environment variables
  • No passwords in .env files
  • Password only stored in Docker volume
  • Password file readable only by containers that need it
  • Mounted read-only where possible
  • Not logged or printed to console
  • Persists only in Docker volume
  • Password survives container restarts
  • Stored in Docker volume (persists across docker-compose down)
  • Can be backed up and restored
  • Compatible with Docker Swarm secrets
vibecode-webgui/
├── docker-compose.yml # Orchestration with auto-password
├── scripts/
│ ├── openvscode-entrypoint.sh # Auto-configures settings from password
│ └── init-password.sh # (unused - kept for reference)
├── /tmp/openvscode-dockerfile/
│ ├── Dockerfile # Custom image with entrypoint
│ └── openvscode-entrypoint.sh # Copy of entrypoint script
└── init-db.sql # Database initialization
services:
# Generates password on first run
init-secrets:
image: alpine:latest
volumes:
- secrets:/run/secrets
command: >
sh -c "
if [ ! -f /run/secrets/db_password ]; then
echo 'Generating random database password...';
apk add --no-cache openssl > /dev/null 2>&1;
openssl rand -base64 32 > /run/secrets/db_password;
chmod 644 /run/secrets/db_password;
echo 'Password generated successfully';
else
echo 'Using existing password';
fi
"
postgres:
image: pgvector/pgvector:pg16
environment:
POSTGRES_PASSWORD_FILE: /run/secrets/db_password
POSTGRES_DB: workspace_rag
volumes:
- postgres_data:/var/lib/postgresql/data
- secrets:/run/secrets:ro
depends_on:
init-secrets:
condition: service_completed_successfully
openvscode:
image: openvscode-with-rag:latest
volumes:
- secrets:/run/secrets:ro
depends_on:
init-secrets:
condition: service_completed_successfully
postgres:
condition: service_healthy
volumes:
postgres_data:
secrets: # Stores the generated password
Terminal window
# See what password was generated
docker exec openvscode-server cat /run/secrets/db_password
Terminal window
# Stop services
docker-compose down
# Remove secrets volume (deletes old password)
docker volume rm vibecode-webgui_secrets
# Start services (generates new password)
docker-compose up -d

Warning: This will generate a new password. You’ll need to re-index your workspace.

Terminal window
# Save password to file
docker exec openvscode-server cat /run/secrets/db_password > db_password_backup.txt
# Restore password (before first startup)
docker volume create vibecode-webgui_secrets
docker run --rm -v vibecode-webgui_secrets:/secrets -v $(pwd):/backup alpine \
sh -c "cp /backup/db_password_backup.txt /secrets/db_password"

If you need to set a specific password:

Terminal window
# Create secrets volume with custom password
docker volume create vibecode-webgui_secrets
echo "your-custom-password-here" | docker run --rm -i -v vibecode-webgui_secrets:/secrets alpine \
sh -c "cat > /secrets/db_password"
# Start services (will use your password)
docker-compose up -d

Symptom: init-secrets container fails

Check:

Terminal window
docker logs init-secrets

Fix:

Terminal window
# Recreate init-secrets
docker-compose up -d --force-recreate init-secrets

Symptom: Settings file missing or empty

Check:

Terminal window
docker logs openvscode-server | grep -i password

Fix:

Terminal window
# Ensure secrets volume is mounted
docker inspect openvscode-server | grep -A 10 Mounts
# Recreate container
docker-compose up -d --force-recreate openvscode

Cause: Old container using old image/entrypoint

Fix:

Terminal window
# Rebuild image
cd /tmp/openvscode-dockerfile
docker build -t openvscode-with-rag:latest .
# Force recreate container
docker-compose up -d --force-recreate openvscode

You can still customize other settings via .env:

Terminal window
# .env file
POSTGRES_USER=postgres
POSTGRES_DB=workspace_rag
POSTGRES_PORT=5432
OPENVSCODE_PORT=3000
# Note: POSTGRES_PASSWORD is NOT needed - auto-generated!

For production, use Docker Swarm’s native secrets:

services:
postgres:
secrets:
- db_password
environment:
POSTGRES_PASSWORD_FILE: /run/secrets/db_password
secrets:
db_password:
external: true # Managed by Swarm

Then create the secret:

Terminal window
openssl rand -base64 32 | docker secret create db_password -

For Kubernetes:

apiVersion: v1
kind: Secret
metadata:
name: db-password
type: Opaque
data:
password: <base64-encoded-password>

❌ Before (Manual Password Configuration)

Section titled “❌ Before (Manual Password Configuration)”
.env
POSTGRES_PASSWORD=password # Hardcoded, version controlled
# docker-compose.yml
environment:
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} # From .env
# Extension
"workspaceRag.pgPassword": "password" # Hardcoded default

Issues:

  • Same password for every installation
  • Password in source control (if .env committed)
  • Easy to forget to change default
  • Security risk
Terminal window
# No .env password needed!
# docker-compose.yml
environment:
POSTGRES_PASSWORD_FILE: /run/secrets/db_password # From volume
# Extension (auto-configured)
# Settings created dynamically with generated password

Benefits:

  • Unique password per installation
  • No passwords in source control
  • Impossible to forget to change
  • Production-ready security

🎉 Zero-configuration secure password management!

Random password generated automatically on first run ✅ Both services auto-configured with same password ✅ No manual steps required - just docker-compose up -dProduction-ready security - 256-bit random passwords ✅ Password persists across restarts in Docker volume ✅ No hardcoded secrets anywhere in codebase

Quick Start:

Terminal window
docker-compose up -d
open http://localhost:3000
# Everything works - password generated and configured automatically!

Access: http://localhost:3000 Status: ✅ Production Ready with Auto-Generated Passwords Security: ✅ 256-bit Cryptographically Secure Random Passwords