Skip to main content
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.

Base Images

There are two main options for base Docker 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:
  1. Smaller Image Size - Only the production bundle and runtime dependencies are in the final image
  2. Faster Builds - Build dependencies are cached in the builder stage
  3. Security - Build tools and source code aren’t included in the production image
  4. Optimization - Separate build and runtime environments

Building the Docker Image

1

Create Dockerfile

Create a Dockerfile in the root of your Meteor project with the example above.
2

Build the Image

Build the Docker image:
3

Test Locally

Run the container locally to test:

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 URI
  • PORT - 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
Run with Docker Compose:

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:
If you use a mismatched version of Node or architecture when deploying your application, you will encounter errors. Meteor 3.x requires Node.js 20.x.

Node.js Version

To find out which version of Node you should use:
  • Run meteor node -v in your development environment
  • Check the .node_version.txt file within the bundle
  • For Meteor 3.x, you’ll need Node.js 20.x
The Dockerfile example uses 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, run meteor update --npm before meteor npm install in your Dockerfile:

Best Practices

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.
Use specific version tags for base images (e.g., node:20.11-alpine) rather than latest to ensure reproducible builds.
Copy package files before application code so that dependency layers can be cached when only code changes.
Always run your application as a non-root user for better security.
Add health check endpoints and Docker HEALTHCHECK instructions for better orchestration.
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 install completes 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 .dockerignore to 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

Additional Resources