Docs

DigitalOcean

Use dotenvx with DigitalOcean.

Find code examples for this guide on GitHub.

DigitalOcean has multiple deploy paths—droplets, Kubernetes, and App Platform. This guide assumes Docker (the most common path).

Dockerfile

# .dockerignore
.env.keys
# Dockerfile
FROM node:20
WORKDIR /app

RUN curl -sfS https://dotenvx.sh/install.sh | sh

COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000

CMD ["dotenvx", "run", "--", "node", "index.js"]

Encrypt production

# .env.production
HELLO="production"
$ dotenvx encrypt -f .env.production

Commit .env.production. Do not commit .env.keys.

Set decryption key

Set DOTENV_PRIVATE_KEY_PRODUCTION in DigitalOcean's environment variable manager (or pass it into docker run -e), then redeploy. Your app injects env from the encrypted .env.production file.