Skip to content

Instantly share code, notes, and snippets.

@tlongren
Last active June 11, 2019 06:41
Show Gist options
  • Save tlongren/719cb0f921993b62a79b1c16adba205c to your computer and use it in GitHub Desktop.
Save tlongren/719cb0f921993b62a79b1c16adba205c to your computer and use it in GitHub Desktop.
Dockerize a Meteor App
#!/bin/bash
# Taken from https://blog.mvp-space.com/how-to-dockerize-a-meteor-app-with-just-one-script-4bccb26f6ff0
APP_NAME=myapp
APP_DOMAIN=localhost
APP_PORT=3000
SETTINGS_PATH=.config/staging/settings.json
MONGO_URL=localhost
MONGO_PORT=27017
MONGO_DB=myappdb
echo "=> Removing /tmp/${APP_NAME}"
rm -R /tmp/${APP_NAME}
echo "=> Executing Meteor Build..."
meteor build \
--allow-superuser \
--directory /tmp/${APP_NAME} \
--server=http://${APP_DOMAIN}:${APP_PORT}/
echo "=> Copying settings file..."
cp ${SETTINGS_PATH} /tmp/${APP_NAME}/bundle/settings.json
echo "=> Moving to /tmp/${APP_NAME}/bundle"
cd /tmp/${APP_NAME}/bundle
# Create package.json
echo "=> Creating package.json..."
cat > package.json <<- "EOF"
{
"name": "app",
"version": "1.0.0",
"scripts": {
"start": "METEOR_SETTINGS=$(cat settings.json) node main.js"
}
}
EOF
# Create the Dockerfile
echo "=> Creating Dockerfile..."
cat > Dockerfile <<EOF
# Pull base image.
FROM mhart/alpine-node:4
# Install build tools to compile native npm modules
RUN apk add — update build-base python
# Create app directory
RUN mkdir -p /usr/app
COPY . /usr/app
RUN cd /usr/app/programs/server && npm install — production
WORKDIR /usr/app
ENV PORT=3000
ENV MONGO_URL=mongodb://$MONGO_URL:$MONGO_PORT/$MONGO_DB
ENV ROOT_URL=http://$APP_DOMAIN:$APP_PORT/
CMD [ "npm", "start" ]
EXPOSE 3000
EOF
# Build the docker image
echo "=> Building docker image..."
docker stop ${APP_NAME}
docker rm -f ${APP_NAME}
docker rmi -f ${APP_NAME}
Once everything is out of the way we can build the image
docker build -t ${APP_NAME} .
# Start the container
echo "=> Starting ${APP_NAME} container..."
docker run -d — name ${APP_NAME} -p ${APP_PORT}:3000 ${APP_NAME}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment