Manage secrets in Docker containers using XtraSecurity.
# Fetch secrets first
xtra get database_url > /tmp/.env
xtra get api_key >> /tmp/.env
# Run container with secrets
docker run \
--env-file /tmp/.env \
-e XTRA_API_KEY="sk_live_xxx" \
myapp:latest
version: '3.9'
services:
app:
image: myapp:latest
environment:
XTRA_API_KEY: ${XTRA_API_KEY}
DATABASE_URL: ${DATABASE_URL}
API_KEY: ${API_KEY}
env_file:
- .env.production
ports:
- "3000:3000"
depends_on:
- postgres
postgres:
image: postgres:15
environment:
POSTGRES_PASSWORD: ${DB_PASSWORD}
volumes:
- postgres_data:/var/lib/postgresql/data
volumes:
postgres_data:
# Fetch all secrets into .env
xtra export --format env > .env.production
# Don't commit .env files
echo ".env.production" >> .gitignore
Create entrypoint.sh:
#!/bin/bash
set -e
# Fetch secrets on startup
xtra get database_url > /run/secrets/db_url
xtra get api_key > /run/secrets/api_key
# Export as environment variables
export DATABASE_URL=$(cat /run/secrets/db_url)
export API_KEY=$(cat /run/secrets/api_key)
# Start application
exec "$@"
Update Dockerfile:
FROM node:18
WORKDIR /app
RUN npm install -g @xtrasecurity/cli
COPY entrypoint.sh /
RUN chmod +x /entrypoint.sh
COPY . .
RUN npm install
ENTRYPOINT ["/entrypoint.sh"]
CMD ["npm", "start"]
Complete guide to integrating XtraSecurity with GitHub Actions. Secure your CI/CD pipeline by fetching secrets from XtraSecurity in GitHub workflows.
Use XtraSecurity as a secrets provider in Kubernetes. External Secrets Operator integration for automatic secret syncing.
Integrate XtraSecurity secrets with Jenkins pipelines. Secure your Jenkins CI/CD with declarative and scripted pipelines.