Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/dokploy/dokploy/llms.txt

Use this file to discover all available pages before exploring further.

Environment variables allow you to configure your applications without modifying code. Dokploy provides secure management of runtime variables, build arguments, and build secrets.

Environment Variable Types

Dokploy supports three types of variables:

Environment Variables

Runtime configuration available in running containers

Build Arguments

Variables used during Docker image build

Build Secrets

Sensitive build-time data not persisted in images

Environment Variables

Runtime variables available to your application containers.

Configuring Environment Variables

1

Navigate to Environment

Open your application and go to the “Environment” tab.
2

Add Variables

Enter variables in KEY=value format (one per line):
NODE_ENV=production
PORT=3000
DATABASE_URL=postgresql://user:pass@db:5432/mydb
REDIS_URL=redis://redis:6379
API_KEY=abc123xyz789
LOG_LEVEL=info
3

Save Configuration

Click “Save Environment” to persist changes.
4

Apply Changes

Redeploy or restart the application to apply new variables:
Restart: Quick update (uses existing image)
Redeploy: Full rebuild with new variables

Variable Formats

NODE_ENV=production
PORT=3000
ENABLE_CORS=true
MAX_CONNECTIONS=100

Project-Level Environment Variables

Define variables shared across all services in a project:
1

Navigate to Project Settings

Open your project settings.
2

Configure Project Variables

# Available to ALL services in this project
REGION=us-east-1
ENVIRONMENT=production
LOG_LEVEL=info
SENTRY_DSN=https://abc@sentry.io/123
3

Service-Level Override

Service-specific variables override project variables:
# Project level
LOG_LEVEL=info

# Service level (overrides project)
LOG_LEVEL=debug

# Result in service container
LOG_LEVEL=debug
Project variables are merged with service variables. Service variables take precedence.

Environment File Generation

Control whether Dokploy creates a .env file in your container:
Create .env file: true ✅
Dokploy creates /app/.env with:
NODE_ENV=production
PORT=3000
DATABASE_URL=postgresql://...
Your application can load it:
// Node.js
require('dotenv').config();

// Python
from dotenv import load_dotenv
load_dotenv()

Build Arguments

Variables available during Docker image build process.

Configuring Build Arguments

# Build Arguments (one per line)
NODE_ENV=production
BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
VERSION=1.2.3
API_URL=https://api.production.com
ENABLE_SOURCEMAPS=false

Using in Dockerfile

# Declare arguments
ARG NODE_ENV
ARG BUILD_DATE
ARG VERSION
ARG API_URL

FROM node:18-alpine

# Use during build
RUN echo "Building version ${VERSION} at ${BUILD_DATE}"

# Set as environment variables (optional)
ENV NODE_ENV=${NODE_ENV}
ENV NEXT_PUBLIC_API_URL=${API_URL}

# Use in build commands
RUN if [ "$NODE_ENV" = "production" ]; then \
      npm run build:prod; \
    else \
      npm run build:dev; \
    fi

# Label the image
LABEL version="${VERSION}" \
      build.date="${BUILD_DATE}"

COPY . .

Common Use Cases

# Build Arguments
NODE_ENV=production
NEXT_PUBLIC_API_URL=https://api.production.com
NEXT_PUBLIC_SENTRY_DSN=https://abc@sentry.io/123
ARG NODE_ENV
ARG NEXT_PUBLIC_API_URL
ARG NEXT_PUBLIC_SENTRY_DSN

ENV NODE_ENV=${NODE_ENV}
ENV NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL}
ENV NEXT_PUBLIC_SENTRY_DSN=${NEXT_PUBLIC_SENTRY_DSN}

RUN npm run build
# Build Arguments
ENABLE_SOURCEMAPS=false
MINIFY=true
OPTIMIZE_IMAGES=true
ARG ENABLE_SOURCEMAPS
ARG MINIFY

RUN npm run build -- \
  --sourcemaps=${ENABLE_SOURCEMAPS} \
  --minify=${MINIFY}
# Build Arguments
VERSION=1.2.3
GIT_COMMIT=abc123
BUILD_DATE=2024-01-15T10:30:00Z
ARG VERSION
ARG GIT_COMMIT
ARG BUILD_DATE

LABEL app.version="${VERSION}" \
      app.commit="${GIT_COMMIT}" \
      app.build-date="${BUILD_DATE}"

# Embed in application
RUN echo "{\"version\":\"${VERSION}\",\"commit\":\"${GIT_COMMIT}\"}" > /app/version.json
Build arguments are visible in the image history. Don’t use them for secrets.
docker history myapp:latest
# Build arguments are visible here! ⚠️

Build Secrets

Secure way to pass sensitive data during builds without persisting in the image.

Configuring Build Secrets

# Build Secrets (one per line)
NPM_TOKEN=npm_abc123xyz789
GITHUB_TOKEN=ghp_xyz789abc456
PIP_INDEX_URL=https://user:pass@pypi.company.com/simple
COMPOSER_AUTH={"github-oauth": {"github.com": "token123"}}

Using in Dockerfile

FROM node:18-alpine

WORKDIR /app

# Copy package files
COPY package*.json ./

# Install with secret NPM token
RUN --mount=type=secret,id=NPM_TOKEN \
    NPM_TOKEN=$(cat /run/secrets/NPM_TOKEN) && \
    echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > .npmrc && \
    npm install && \
    rm .npmrc

COPY . .
RUN npm run build
The secret is mounted during build but NOT stored in any image layer.

Build Secrets vs Build Arguments

When to use:
  • API tokens
  • Registry credentials
  • SSH keys
  • Private package tokens
Security:
 Not stored in image layers
 Not visible in docker history
 Automatically cleaned up
 Safe for sensitive data
Example:
RUN --mount=type=secret,id=NPM_TOKEN \
    npm install

Preview-Specific Variables

Configure environment variables specifically for preview deployments:
# Preview Environment Variables
NODE_ENV=preview
DATABASE_URL=postgresql://preview_user:pass@db:5432/preview_db
ENABLE_DEBUG=true
DISABLE_ANALYTICS=true
API_URL=https://${DOKPLOY_DEPLOY_URL}/api
${DOKPLOY_DEPLOY_URL} is automatically replaced with the preview URL.

Variable Precedence

When the same variable is defined in multiple places:
1. Service Environment Variables (highest priority)

2. Preview Environment Variables (for preview deployments)

3. Project Environment Variables

4. System Defaults (lowest priority)
Example:
# Project level
LOG_LEVEL=info
DATABASE_URL=postgresql://prod_db

# Service level
LOG_LEVEL=debug

# Result in container
LOG_LEVEL=debug (service overrides project)
DATABASE_URL=postgresql://prod_db (from project)

Security Best Practices

Use Build Secrets

For sensitive build-time data:
RUN --mount=type=secret,id=TOKEN

Avoid Hardcoding

Never commit secrets to code:
 API_KEY="abc123" in code
 API_KEY in environment

Rotate Credentials

Regularly update sensitive values:
1. Generate new token
2. Update in Dokploy
3. Redeploy services
4. Revoke old token

Limit Access

Restrict who can view/edit variables:
- Role-based access control
- Audit logs
- Member permissions

Accessing Variables in Applications

// Access environment variables
const port = process.env.PORT || 3000;
const dbUrl = process.env.DATABASE_URL;
const apiKey = process.env.API_KEY;

// Using dotenv (if .env file created)
require('dotenv').config();
console.log(process.env.NODE_ENV);

Troubleshooting

Variable Not Available in Container

1

Check Variable Name

# Verify exact name (case-sensitive)
DATABASE_URL
database_url
2

Restart/Redeploy

Changes require:
- Restart (quick, uses existing image)
- Redeploy (full rebuild)
3

Verify in Container

# Access container terminal
docker exec -it myapp sh

# List all environment variables
env | grep DATABASE_URL

# Check .env file (if created)
cat .env

Build Failing with Secrets

Error: secret required but no secret provider

Solution:
1. Verify build secrets are configured in Dokploy
2. Check secret IDs match Dockerfile:
   
   Dokploy: NPM_TOKEN=abc123
   Dockerfile: --mount=type=secret,id=NPM_TOKEN
   
3. Ensure using BuildKit:
   export DOCKER_BUILDKIT=1

Special Characters Breaking Variables

# Problem
PASSWORD=p@ss$word  # $ interpreted as variable

# Solution: Use quotes
PASSWORD="p@ss$word"

# Or escape special characters
PASSWORD=p@ss\$word

Next Steps

Applications

Learn about deploying applications

Rollbacks

Understand rollback functionality