Dockerize Meteor Application

January 20, 2017
docker, docker-compose, meteor

Let’s start with building our meteor project to make it ready for the production environment. Create a file build-docker.sh in the project’s root directory.

#!/bin/sh
set -e

# meteor doesn't want the build directory to be present under the root folder
meteor build --architecture=os.linux.x86_64 ../build

cd ../build && tar -zxvf <project_name>.tar.gz && cd -
docker build -t <username>/<image_name> .
FROM node:7.4.0

COPY ../build/bundle /app
RUN cd /app/programs/server && npm install
ENV PORT=80
EXPOSE 80

CMD node /app/main.js

Running the build-docker.sh script will create the docker image. If you are using this locally, you can use docker-compose to easily link the application to a containerized database.

version: '2'

services:
  mongo:
    image: mongo:3.4.0
    ports:
      - "27030:27017"
    volumes:
      - $HOME/Data/mongodb:/data/db
    command: mongod --smallfiles

  web:
    image: <username>/<image_name>
    ports:
      - "8001:80"
    environment:
      - MONGO_URL=mongodb://mongo:27017/tasks
      - ROOT_URL=http://appname.local
  1. Database(mongo)
  1. Application(web)