
If you are building Docker applications, Stop Using .env Files for Docker Secrets and consider Docker Secret Operator (DSO) for secure credential management. DSO eliminates plaintext credentials on disks by caching secrets in RAM via an agent system, supporting automatic rotation across AWS, Azure, and HashiCorp Vault without needing Kubernetes.
When you start a new project, dropping a local .env file to manage database credentials feels like the only logical move. However, as your infrastructure scales to multiple Docker hosts, Stop Using .env Files for Docker Secrets becomes critical for security and compliance. Manually syncing .env files across VMs leads to "secret drift," where some containers are using old credentials while others are patchy.
For those of us running Docker or Docker Compose on bare metal or managed VMs—without the overhead of a full Kubernetes cluster—the options have historically been messy. You either inherit the complexity of Kubernetes-native solutions designed for microservices, or you suffer through manual synchronization and shell scripts.
Docker Secret Operator (DSO) is an open-source project built specifically to close this gap. It solves the "Docker without Kubernetes" secret management problem by introducing a background agent and a CLI plugin that injects secrets directly into your container environment, keeping them off the disk entirely.
The intuition behind DSO is simple: treat the container's environment variables exactly as you would trust them, but manage the source of truth externally from the host machine.
Maintaining Stop Using .env Files for Docker Secrets requires a shift from file-based management to runtime injection. DSO accomplishes this through a two-part architecture:
PATH. When you run docker dso up, it connects to the Agent via a secure Unix domain socket, fetches the mapped secrets, and injects them into the container process during startup.This means your application sees DB_PASSWORD, but that string exists nowhere in your file system; it is destroyed as soon as the container stops.
"Most DevOps engineers stick with
.envfiles because 'that's how Docker is done.' But if you care about security,.envfiles are not just bad practice—they are a liability. Hardcoding credentials into Git commits because.envmanagement is a pain is a sign of architectural laziness, not efficiency. DSO forces you to manage secrets like a production environment, even if your app is just a simple script."
Using .env files for Docker secrets implies that these files must be added to .gitignore, rotated manually, and copied to every host running a container. This workflow is error-prone.
DSO removes the file from the equation entirely. Here is the technical flow:
docker run or docker compose up event, requests the specific secrets needed for that service, and overlays the environment list before the container runtime initializes.| Feature | .env Files (Plain Docker) | Docker Swarm Secrets | DSO (Docker Secret Operator) |
|---|---|---|---|
| Storage | Plaintext on Disk | Plaintext (Encrypted at Rest) | In-Memory (RAM) Only |
| Cloud Sync | Manual (Copy/Paste) | None | Native (AWS/Azure/Vault) |
| Rotation | Manual Restart/Deploy | Manual / Manual Restart | Automatic / Rolling |
| Authorization | OS File Permissions | Swarm RBAC | Cloud IAM / K8s RBAC |
| Management | Local Flat Files | Distributed File System | Distributed Agent + CLI |
If you are ready to Stop Using .env Files for Docker Secrets, here is how to implement DSO in a production workflow on Ubuntu/Debian.
Run the official installer script to set up the Agent and the CLI plugin:
curl -fsSL https://raw.githubusercontent.com/docker-secret-operator/dso/main/install.sh | sudo bash
Create the configuration file at /etc/dso/dso.yaml. You need to define your cloud provider connection and the secrets you want to track.
providers:
aws-prod:
type: aws
region: us-east-1
auth:
method: iam_role # Use EC2 Instance Profile for production
agent:
cache: true
watch:
polling_interval: 5m # Check for updates every 5 minutes
defaults:
inject:
type: env
rotation:
enabled: true
strategy: rolling # Default strategy for all secrets
secrets:
- name: arn:aws:secretsmanager:us-east-1:123456789:secret:my-db-credentials
provider: aws-prod
rotation:
strategy: restart # Override for this specific secret
mappings:
DB_USER: MYSQL_USER
DB_PASSWORD: MYSQL_PASSWORD
Modify your docker-compose.yaml. The magic happens by removing the values and leaving just the keys that DSO will fill.
services:
api:
image: my-app:latest
environment:
- DB_USER # DSO Agent fetches this from AWS
- DB_PASSWORD # DSO Agent fetches this from AWS
Stop using standard Docker commands. Use the DSO CLI to orchestrate your stack.
# Start the agent (run once)
sudo systemctl start dso-agent.service
# Run your stack
docker dso up -d
If DSO doesn't fit your stack, consider:
Q: Does DSO work with Windows? A: Currently, the CLI plugin and Agent are optimized for Linux/Unix systems (Ubuntu/Debian). Windows compatibility is planned for future releases.
Q: Can DSO handle millions of secrets? A: DSO is optimized for specific secrets required for service startup (application configuration). It is not a generic secret store for arbitrary data. Use a dedicated store if you need to store arbitrary JSON blobs.
Q: What happens if the DSO Agent is down? A: The agent maintains an in-memory cache. If the agent restarts or goes down, secrets are lost until the agent refreshes them. If your application expects secrets immediately on launch, this can cause startup failures.
Q: Is this safer than Kubernetes Secrets? A: From a storage perspective, yes. Kubernetes Secrets are base64 encoded and stored in etcd; they are not encrypted at rest by default unless you use external tools. DSO keeps secrets in RAM and varies them frequently, rendering them invisible to disk scans.
If you are still strictly Stop Using .env Files for Docker Secrets because you don't run Kubernetes, you have been accepting a security compromise. Docker Secret Operator (DSO) brings parity to simpler deployments, giving you the automatic rotation and cloud-integration benefits that large teams take for granted.
Check out the repository to give it a spin: GitHub: docker-secret-operator/dso.