Docker Prerequisites & Best Practices for Flux
Install Docker, create optimized Dockerfiles, multi-stage builds, image registries, containerData volumes, and common mistakes.
Docker Prerequisites & Best Practices for Flux
Before deploying any application on FluxCloud, you need a working Docker environment, a Docker Hub account, and a Zelcore wallet with FLUX tokens. This guide covers everything you need to set up from scratch β plus the Docker best practices that make or break a successful Flux deployment.
Installing Docker
Install Docker on Ubuntu/Debian
# Update packages and install prerequisites
sudo apt update && sudo apt install -y ca-certificates curl gnupg
# Add Docker GPG key and repository
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# Install Docker
sudo apt update && sudo apt install -y docker-ce docker-ce-cli containerd.io
# Add your user to the docker group (avoids needing sudo)
sudo usermod -aG docker $USER
# Verify installation
docker --versionOn macOS and Windows, download and install Docker Desktop from docker.com. It includes Docker Engine, CLI, and Docker Compose in a single installer.
Docker Hub Account Setup
- 1
Create a Docker Hub account
Sign up at hub.docker.com. Choose a username carefully β it becomes your image namespace (e.g., yourusername/my-app).
- 2
Log in via CLI
Run docker login and enter your credentials. This stores an auth token for pushing images.
- 3
Keep images public
By default, Flux nodes need to pull your Docker image from a public repository. Private images require Enterprise deployment mode (additional fees).
Login to Docker Hub
docker login
# Enter your Docker Hub username and password/tokenWriting an Optimized Dockerfile for Flux
Docker images deployed on Flux are pulled by every node that runs your app. Smaller images mean faster deployment, less bandwidth usage, and quicker scaling. Follow these best practices:
- β’Use alpine base images: node:20-alpine (50MB) instead of node:20 (350MB). Same for python:3.12-alpine, golang:1.22-alpine, etc.
- β’Multi-stage builds: Build in one stage, copy only the compiled output to a minimal runtime stage. Dramatically reduces final image size.
- β’Minimize layers: Combine RUN commands with && to reduce the number of Docker layers.
- β’Use .dockerignore: Exclude node_modules, .git, .env, test files β anything not needed at runtime.
- β’Set proper EXPOSE: Declare the port your app listens on. This must match your Flux spec containerPorts.
- β’Use CMD, not ENTRYPOINT: CMD is easier to override and debug. Use exec form: CMD ["node", "server.js"].
- β’Add health checks: HEALTHCHECK instructions help Flux monitor your container health.
Optimized Dockerfile β Node.js example
# Build stage
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci --production
COPY . .
# Runtime stage
FROM node:20-alpine
WORKDIR /app
COPY --from=builder /app .
EXPOSE 3000
HEALTHCHECK --interval=30s --timeout=3s \
CMD wget -qO- http://localhost:3000/health || exit 1
CMD ["node", "server.js"]Optimized Dockerfile β Python Flask example
FROM python:3.12-alpine
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 5000
CMD ["python", "app.py"]Building, Tagging & Pushing
Build and push your Docker image
# Build the image
docker build -t yourusername/my-flux-app:latest .
# Test locally
docker run -p 3000:3000 yourusername/my-flux-app:latest
# Push to Docker Hub
docker push yourusername/my-flux-app:latestAlways test your image locally with docker run before deploying to Flux. If it doesn't work locally, it won't work on the network. Verify the correct port is exposed and the app starts without errors.
Persistent Data with containerData
Flux apps can persist data using the containerData field in the app specification. This mounts a volume at the specified path inside the container. Data stored here survives container restarts on the same node but does not automatically sync between instances unless you use a database with built-in replication.
containerData in app spec
{
"containerData": "/appdata"
}Common Docker Mistakes on Flux
- 1
Image is private
Flux nodes can't pull private images unless you use Enterprise mode. Make sure your Docker Hub repository is set to public.
- 2
Wrong port exposed
The EXPOSE port in your Dockerfile must match the containerPorts in your Flux spec. Mismatches cause the app to appear unreachable.
- 3
Image too large
Images over 1GB take too long to pull and may fail on nodes with slower connections. Use alpine bases and multi-stage builds to stay under 200MB.
- 4
No health endpoint
Without a health check, Flux can't distinguish a crashed app from a slow-starting one. Always add a /health endpoint.
- 5
Hardcoded configuration
Use environment variables for configuration (database URLs, API keys, ports) rather than hardcoding. Flux supports environmentParameters in the spec.
Other articles in FluxCloud Advanced Deployment
Compose v4: Multi-Component Applications
Deploy up to 5 components with Flux Compose v4 β internal DNS, inter-component communication, ports, and environment variables.
Enterprise Deployments (Private Images, Secrets & Static IP)
Enterprise mode features β private Docker registries, secrets management, static IPs, node targeting, and pricing.
Deploy with Git (CI/CD & Auto-Deploy)
Auto-deploy from GitHub/GitLab/Bitbucket β webhooks, polling, zero-downtime updates, rollback, and CI/CD integration.
Flux-Orbit: Zero-Config Universal Deployment
Deploy any project without a Dockerfile β auto-detection for Node.js, Python, Rust, Go, Java, Bun, Ruby, and static sites.
Shared Databases & Auto-Replication
Deploy databases on Flux with persistent storage β MongoDB, PostgreSQL, Redis replication strategies and backup patterns.
Tiered Resources, Spec Builder & Cost Calculator
Basic/Super/BAMF resource tiers, Visual Spec Builder, Cost Calculator, pricing model, and cloud cost comparison.
App Troubleshooting & Post-Deployment Management
Diagnose deployment failures, domain issues, DB connection problems β plus updating specs, monitoring, and app lifecycle management.