Find code examples for this guide on GitHub.
Initial setup
Create a Hello World app, a Dockerfile, and fly.toml, then deploy.
# Dockerfile
FROM node:20
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["node", "index.js"]
# .dockerignore
.env.keys
[http_service]
internal_port = 3000
flyctl launch
flyctl deploy
Run dotenvx
Install dotenvx in your Dockerfile and prepend your app command with dotenvx run --.
# Dockerfile
FROM node:20
WORKDIR /app
# Install dotenvx
RUN curl -sfS https://dotenvx.sh/install.sh | sh
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
# Prepend dotenvx run
CMD ["dotenvx", "run", "--", "node", "index.js"]
If you prefer, install from GitHub Releases or view the install.sh file before executing.
Encrypt production
# .env.production
HELLO="production"
$ dotenvx encrypt -f .env.production
Commit .env.production. Do not commit .env.keys.
Set decryption key
flyctl secrets set DOTENV_PRIVATE_KEY_PRODUCTION='your-private-key'
flyctl deploy
Your app restarts and env is injected from the encrypted .env.production file.