Overview
Mizen includes Docker support for containerized deployment. While the project doesn’t currently include a complete Dockerfile in the repository, this guide shows you how to run Mizen with Docker.Prerequisites
- Docker installed and running
- Docker Compose (optional, for multi-container setups)
- Basic understanding of Docker concepts
Quick Start with Docker
The project includes npm scripts for common Docker operations:Docker Build
Thedocker:build script builds a Docker image named parse-n-plate:
Docker Run
Thedocker:run script runs the container with environment variables:
What This Does
-p 3000:3000- Maps port 3000 from the container to port 3000 on your host--env-file .env.local- Loads environment variables from.env.localrecipe-app- The name of the container to run
Creating a Dockerfile
If you need to create a Dockerfile for your project, here’s a recommended Next.js Dockerfile:Dockerfile
Docker Ignore
The project includes a.dockerignore file to exclude unnecessary files from the Docker build context:
.dockerignore
Environment files are excluded from the Docker image for security. You must provide them at runtime using
--env-file or environment variable flags.Environment Variables in Docker
There are multiple ways to provide environment variables to Docker containers:Method 1: Using --env-file
The recommended approach for local development:
Method 2: Individual Environment Variables
Pass variables directly:Method 3: Docker Compose
Create adocker-compose.yml file for easier management:
docker-compose.yml
Multi-Stage Build Benefits
The recommended Dockerfile uses a multi-stage build approach:Smaller Image
Only production dependencies and built files are included in the final image.
Better Security
Reduced attack surface by excluding development tools and source code.
Faster Builds
Docker caching optimizes rebuild times when dependencies don’t change.
Production Deployment
Building for Production
Health Checks
Add a health check to your Dockerfile:Common Docker Commands
View running containers
View running containers
View container logs
View container logs
Execute commands in container
Execute commands in container
Stop a container
Stop a container
Remove a container
Remove a container
Remove an image
Remove an image
Prune unused resources
Prune unused resources
Troubleshooting
Port already in use
Port already in use
Error:
Bind for 0.0.0.0:3000 failed: port is already allocatedSolution: Either stop the process using port 3000 or map to a different port:Environment variables not loaded
Environment variables not loaded
Issue: Application can’t access environment variablesSolution:
- Verify
.env.localexists and contains the required variables - Ensure
--env-fileflag points to the correct file - Check file permissions:
chmod 644 .env.local - For Next.js public variables, ensure they’re prefixed with
NEXT_PUBLIC_
Build fails on dependencies
Build fails on dependencies
Error:
npm ERR! code ENOTFOUND or similar during buildSolution:- Check your internet connection
- Verify
package.jsonandpackage-lock.jsonare present - Try clearing Docker build cache:
docker build --no-cache -t mizen .
Container exits immediately
Container exits immediately
Issue: Container starts but exits right awaySolution:
- Check logs:
docker logs <container-id> - Verify the CMD or ENTRYPOINT in your Dockerfile
- Ensure required environment variables are set
- Check for application errors in the logs
Docker Compose with Database
If you want to run Mizen with a local database for development:docker-compose.yml
Best Practices
Use Specific Versions
Always specify exact Node.js versions in your Dockerfile (e.g.,
node:24.4.1-alpine) for reproducible builds.Optimize Layer Caching
Copy
package.json before source code so dependency layers are cached when code changes.Use Alpine Images
Alpine-based images are smaller and more secure than standard images.
Run as Non-Root
Always create and use a non-root user in production containers for security.
Next Steps
Environment Setup
Configure environment variables for Docker containers
Installation
Local development setup without Docker