To orchestrate your own container-based deployment, you can use Docker to package and run your Meteor application. This approach provides flexibility and works with any container orchestration platform like Kubernetes, Docker Swarm, or AWS ECS.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/meteor/meteor/llms.txt
Use this file to discover all available pages before exploring further.
Base Images
There are two main options for base Docker images:- Official Node.js images - Use as a base for your custom Dockerfile
- meteor/meteor-base - Official Meteor base images
Dockerfile Example
Here’s a basic Dockerfile example for a Meteor 3 application using a multi-stage build:Multi-Stage Build Benefits
The multi-stage build approach provides several advantages:- Smaller Image Size - Only the production bundle and runtime dependencies are in the final image
- Faster Builds - Build dependencies are cached in the builder stage
- Security - Build tools and source code aren’t included in the production image
- Optimization - Separate build and runtime environments
Building the Docker Image
Environment Variables
When running your Docker container, you need to set these environment variables:ROOT_URL- The base URL for your Meteor project (e.g.,https://my-app.com)MONGO_URL- MongoDB connection string URIPORT- The port at which the application is running (default: 3000)METEOR_SETTINGS- (Optional) Stringified JSON settings object
Example with Environment Variables
Docker Compose
For local development or simple deployments, you can use Docker Compose to manage both your Meteor app and MongoDB:docker-compose.yml
Architecture-Specific Builds
It’s important to build your bundle for the correct architecture. If deploying to a Linux server, ensure you build for the correct platform:Node.js Version
To find out which version of Node you should use:- Run
meteor node -vin your development environment - Check the
.node_version.txtfile within the bundle - For Meteor 3.x, you’ll need Node.js 20.x
node:20-alpine to match Meteor 3.x requirements.
Optimizing the Dockerfile
Here are some optimizations you can add to your Dockerfile:Layer Caching
Health Check
Non-Root User
Deployment Platforms
Docker containers can be deployed to various platforms:Kubernetes
Create Kubernetes manifests for your deployment:AWS Elastic Beanstalk
You can use mup-aws-beanstalk to deploy Meteor apps to AWS Elastic Beanstalk. It supports autoscaling, load balancing, and zero downtime deploys.DigitalOcean, AWS ECS, Google Cloud Run
All container platforms that support Docker images can run your Meteor application. Just ensure:- Environment variables are properly set
- MongoDB is accessible from the container
- Proper port mapping is configured
- SSL/TLS termination is handled (via load balancer or reverse proxy)
rspack Bundler Considerations
Each Meteor release requires specific minimum versions of NPM packages like Rspack. If these were not committed after upgrading Meteor locally, the Docker environment won’t have them. To fix this, runmeteor update --npm before meteor npm install in your Dockerfile:
Best Practices
Use Multi-Stage Builds
Use Multi-Stage Builds
Always use multi-stage builds to keep your production images small and secure. Build stages should contain build tools, while production stages should only have runtime dependencies.
Pin Version Tags
Pin Version Tags
Optimize Layer Caching
Optimize Layer Caching
Copy package files before application code so that dependency layers can be cached when only code changes.
Run as Non-Root
Run as Non-Root
Always run your application as a non-root user for better security.
Implement Health Checks
Implement Health Checks
Add health check endpoints and Docker HEALTHCHECK instructions for better orchestration.
Use Environment Variables
Use Environment Variables
Never hardcode configuration. Use environment variables for all environment-specific settings.
Troubleshooting
Build Failures
- Ensure all native dependencies have the required build tools (python3, make, g++)
- Check that you’re using the correct Node.js version
- Verify
meteor npm installcompletes successfully
Runtime Errors
- Check environment variables are set correctly
- Verify MongoDB connection string is accessible from the container
- Ensure the correct architecture was used for the build
- Check logs with
docker logs <container-id>
Image Size Too Large
- Use Alpine-based images instead of full distributions
- Implement multi-stage builds properly
- Clean up build artifacts in the same layer they’re created
- Use
.dockerignoreto exclude unnecessary files
Performance Issues
- Ensure proper resource limits are set
- Use production MongoDB with proper indexing
- Consider using a CDN for static assets
- Monitor container metrics