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> .
meteor buildwill output
.tar.gz file into the directory `build` in the project's parent directory.
tarwill unzip the archive and extract out the bundle directory. We need to add this bundle directory to the docker image.
docker buildwill try to create a docker project using the project directory as the context. So we need to add
Dockerfileto the project directory.
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
COPYwill add the bundle folder to the docker image under /app directory.
RUNwill install the required npm dependencies.
ENVwill set the port the server listens to inside the container.
EXPOSEwill make this port available to be linked outside the container.
CMDwill start our server when docker container of this image is run.
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
- We are exposing the database on port 27030 to the host machine
- $HOME/Data/mongodb is mounted on /data/db to persist the data on host machine
- We are exposing our application on port 8081 of local machine
- MONGO_URL is set to connect to mongo service via docker network on port 27017. This is the port that mongodb listens to internally.