Docker / Compose
Resolve secrets at container start — not at build time. Secrets never get baked into your image layers.
Multi-stage Dockerfile
Copy the snapenv binary from the official image and pull at runtime:
dockerfile
FROM ghcr.io/snapenv-io/cli:latest AS snapenv
FROM node:20-alpine
COPY --from=snapenv /usr/local/bin/snapenv /usr/local/bin/snapenv
WORKDIR /app
COPY . .
RUN npm ci
# Pull secrets at container start, then launch the app
CMD snapenv pull --env prod && node dist/server.jsSet SNAPENV_TOKEN and SNAPENV_PROJECT as environment variables when running the container:
bash
docker run \
-e SNAPENV_TOKEN=snp_live_... \
-e SNAPENV_PROJECT=4fac4b02-... \
my-app:latestDocker Compose with env_file
Generate .env before compose up:
yaml
# compose.yml
services:
app:
build: .
env_file: .envbash
# deploy script
snapenv pull --env prod && docker compose up -dNotes
- Never pass secrets as build arguments (
ARG) — they appear indocker history - Use
--stdoutto pipe directly without writing a file:snapenv pull --env prod --stdout > .env - For Kubernetes, prefer the operator over Docker-style patterns