CyCoreSystems / docker-meteor

Dockerfile and script for running Meteor on Docker
MIT License
120 stars 73 forks source link

Meteor 1.8+

We are working on a more modern system for this package which will integrate the benefits of the multi-stage builder. In the mean time, however, I invite you to take a look at our new Dockerfile generator.

We have developed a multi-stage Dockerfile which provides:

To generate a multi-stage Dockerfile for your Meteor app, you can use the meteor-dockerfilegen tool. Binary releases of this tool are located here.

This tool reads your Meteor application and builds the Dockerfile with appropriate versions of Node and Meteor, as specified by your Meteor application's metadata.

Meteor 1.4+

The latest Docker tag and the master git branch are for Meteor 1.4+. For prior versions of Meteor, please use the legacy tag and branch.

Build tag

In order to keep the size of the image down, the current tag does not include build-essential tools. If you are using modules which do not supply binary versions for your platform, please use the build tag, which does include build-essential.

NOTE build-essential is necessary if you use the bcrypt module, which is used by the accounts-password package, so if you are using password-based logins on your site, you must use the :build Docker tag (build git branch).

Features:

Versions

The Meteor tool (if required; see Modes of Operation below) is downloaded at runtime, so it is no longer packaged and the version of this docker image does not matter for the version of meteor.

You can specify which version of Meteor you want to be installed by setting the RELEASE as required. However, this release of ulexus/meteor does require a minimum version of 1.4 for your Meteor application.

Modes of operation

There are two basic modes of operation for this image: source and pre-bundled. The source method allows the greatest flexibility, since it builds and bundles Meteor on the deployment system inside the same container. However, it also takes much longer and requires a much larger disk footprint.

Source mode

To utilize source mode, define one of SRC_DIR or REPO:

When the container is run, the appropriate version of the Meteor tool will be downloaded and installed, your application will be built/bundled, and then it will be run. This process can take several minutes to complete.

Running without root

As of Meteor 1.4.2, running Meteor as root has been strongly dissuaded. As a result, we now drop root privileges after starting the container. This means that if you are bind-mounting your source or bundle directories, the files must be readable and writable by the container's unprivileged user (UID 1000).

Pre-bundled mode

To utilize the pre-bundled mode, DO NOT define SRC_DIR or REPO. Instead define one of APP_DIR or BUNDLE_DIR:

When the container is run, the Meteor tool will NOT be downloaded. Instead, npm install will be run to resolve any dependencies for the server, and your application will be run directly with NodeJS.

Examples:

git repo with non-default (master) branch

docker run --rm \
  -e ROOT_URL=http://testsite.com \
  -e REPO=https://github.com/yourName/testsite \
  -e BRANCH=testing \
  -e MONGO_URL=mongodb://mymongoserver.com:27017/mydatabase \
  -e MONGO_OPLOG_URL=mongodb://mymongoserver.com:27017/local \
  ulexus/meteor

app source from a local directory on host (/home/user/myapp)

docker run --rm \
  -e ROOT_URL=http://testsite.com \
  -v /home/user/myapp:/home/meteor/src \
  -e MONGO_URL=mongodb://mymongoserver.com:27017/appdb \
  -e MONGO_OPLOG_URL=mongodb://mymongoserver.com:27017/local \
  ulexus/meteor

pre-bundled app from a local directory on host (/home/user/myapp)

docker run --rm \
  -e ROOT_URL=http://testsite.com \
  -v /home/user/myapp:/home/meteor/www \
  -e MONGO_URL=mongodb://mymongoserver.com:27017/appdb \
  -e MONGO_OPLOG_URL=mongodb://mymongoserver.com:27017/local \
  ulexus/meteor

pre-bundled and compressed app from a local directory on host (/home/user/build.tar.gz)

docker run --rm \
  -e ROOT_URL=http://testsite.com \
  -e BUNDLE_FILE=/home/meteor/build.tar.gz \
  -v /home/user/build.tar.gz:/home/meteor/build.tar.gz \
  -e MONGO_URL=mongodb://mymongoserver.com:27017/appdb \
  -e MONGO_OPLOG_URL=mongodb://mymongoserver.com:27017/local \
  ulexus/meteor

local app source directory on host (/home/user/myapp) with specific Meteor release (1.4.2.1)

docker run --rm \
  -e ROOT_URL=http://testsite.com \
  -v /home/user/myapp:/home/meteor/src \
  -e MONGO_URL=mongodb://mymongoserver.com:27017/appdb \
  -e MONGO_OPLOG_URL=mongodb://mymongoserver.com:27017/local \
  -e RELEASE=1.4.2.1 \
  ulexus/meteor

Unit file

There is also a sample systemd unit file in the Github repository.

Build with bundled app

Pre-bundling your Meteor application will make it start much faster and will allow the container to maintain a smaller storage footprint. However, it does require that you build for the same architecture on which you will be deploying.

cd $app_source
meteor build --directory /tmp/export-meteor/build
cat >/tmp/export-meteor/Dockerfile <<ENDHERE
FROM ulexus/meteor
COPY build /home/meteor/www
RUN chown -R meteor:meteor /home/meteor/
ENDHERE
cd /tmp/export-meteor
docker build -t myapp .
docker push myapp

Kubernetes

There is a complete example with build script of building and running a versioned container in kubernetes in the examples directory.