← Home

Deploying Your First Meteor App on a Server with Docker

March 03, 2024

Deploying a Meteor application using Docker can solve many common issues related to environment consistency and dependency management. This guide will walk you through containerizing your Meteor app and deploying it on a server.

Step 1: Dockerize Your Meteor Application

First, create a Dockerfile in the root directory of your Meteor project with the following content:

# Use the official Meteor base image
FROM geoffreybooth/meteor-base:latest

# Set the working directory in the container
WORKDIR /app

# Copy your app's source code into the container
COPY . /app

# Install OS dependencies, if any
RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    python \
    && rm -rf /var/lib/apt/lists/*

# Install NPM packages
RUN meteor npm install

# Build the Meteor app
RUN meteor build --directory /app-build

# Use the Node.js base image to run the app
FROM meteor/node:14.21.4-alpine3.17

WORKDIR /app

# Copy the built app from the previous stage and install production NPM packages
COPY --from=0 /app-build /app
RUN cd /app/bundle/programs/server && npm install

# Expose the port the app runs on
EXPOSE 3000

# Define the command to run your app
CMD ["node", "/app/bundle/main.js"]

Step 2: Build Your Docker Image

Build the Docker image for your app:

docker build -t your-app-name .

Step 3: Run Your Meteor App in a Docker Container

Run your app in a Docker container:

docker run -d -p 3000:3000 your-app-name

Step 4: Deploy Your Dockerized App

Push your Docker image to a container registry and deploy it on your server:

  1. Tag and push your image to Docker Hub:
docker tag your-app-name yourusername/your-app-name:version
docker push yourusername/your-app-name:version
  1. On your server, pull and run your image:
docker pull yourusername/your-app-name:version
docker run -d -p 80:3000 yourusername/your-app-name:version

Docker simplifies deployment, ensuring consistency and solving dependency issues. By following these steps, you can deploy your Meteor app smoothly and efficiently.

In the next blog posts, we will dive deeper into the deployment process, focusing on setting up an Ubuntu server and linking a MongoDB database to your Meteor application. Stay tuned for more insights on deploying and managing your Meteor apps effectively.


Chafik Gharbi Full-stack web and mobile app developer with JavaScript.