diff --git a/Dockerfile-production b/Dockerfile-production new file mode 100644 index 0000000000..9946bf844d --- /dev/null +++ b/Dockerfile-production @@ -0,0 +1,65 @@ +# Build: +# docker build -t meanjs/mean -f Dockerfile-production . +# +# Run: +# docker run -it meanjs/mean +# +# Compose: +# docker-compose -f docker-compose-production.yml up -d + +FROM ubuntu:latest +MAINTAINER MEAN.JS + +# Install Utilities +RUN apt-get update -q && apt-get install -yqq aptitude git traceroute dnsutils tree tcpdump psmisc gcc make build-essential libfreetype6 libfontconfig libkrb5-dev curl sudo + +# Install gem sass for grunt-contrib-sass +RUN apt-get install -y ruby +RUN gem install sass + +# Install NodeJS +RUN curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash - +RUN sudo apt-get install -yq nodejs + +# Install MEAN.JS Prerequisites +RUN npm install --quiet -g grunt-cli gulp bower yo mocha karma-cli pm2 + +RUN mkdir /opt/mean.js +RUN mkdir -p /opt/mean.js/public/lib +WORKDIR /opt/mean.js + +# Copies the local package.json file to the container +# and utilities docker container cache to not needing to rebuild +# and install node_modules/ everytime we build the docker, but only +# when the local package.json file changes. +# Install npm packages +ADD package.json /opt/mean.js/package.json +RUN npm install --quiet --production + +# Install bower packages +ADD bower.json /opt/mean.js/bower.json +ADD .bowerrc /opt/mean.js/.bowerrc +RUN bower install --quiet --allow-root --config.interactive=false + +# Share local directory on the docker container +ADD . /opt/mean.js + +# Machine cleanup +RUN npm cache clean +RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* + +# Set development environment as default +ENV NODE_ENV production + +# Ports generic +EXPOSE 80:80 +EXPOSE 443:443 + +# Port 3000 for MEAN.JS server +EXPOSE 3000:3000 + +# Port 35729 for livereload +EXPOSE 35729:35729 + +# Run MEAN.JS server +CMD ["npm","run-script","start:prod"] diff --git a/README.md b/README.md index 2a015ba8ca..b65198ac7a 100644 --- a/README.md +++ b/README.md @@ -203,6 +203,21 @@ $ $ docker run -p 3000:3000 -p 35729:35729 -v /Users/mdl/workspace/mean-stack/mean/public:/home/mean/public -v /Users/mdl/workspace/mean-stack/mean/app:/home/mean/app --link db:db_1 mean ``` +### Production deploy with Docker + +* Production deployment with compose: +```bash +$ docker-compose -f docker-compose-production.yml up -d +``` + +* Production deployment with just Docker: +```bash +$ docker build -t mean -f Dockerfile-production . +$ docker run -p 27017:27017 -d --name db mongo +$ docker run -p 3000:3000 --link db:db_1 mean +$ +``` + ## Getting Started With MEAN.JS You have your application running, but there is a lot of stuff to understand. We recommend you go over the [Official Documentation](http://meanjs.org/docs.html). In the docs we'll try to explain both general concepts of MEAN components and give you some guidelines to help you improve your development process. We tried covering as many aspects as possible, and will keep it updated by your request. You can also help us develop and improve the documentation by checking out the *gh-pages* branch of this repository. diff --git a/docker-compose-production.yml b/docker-compose-production.yml new file mode 100644 index 0000000000..ec7c70f0d4 --- /dev/null +++ b/docker-compose-production.yml @@ -0,0 +1,40 @@ +version: '2' +services: + web: + restart: always + build: + context: . + dockerfile: Dockerfile-production + container_name: meanjs + ports: + - "8443:8443" + environment: + - NODE_ENV=production + - DB_1_PORT_27017_TCP_ADDR=db + depends_on: + - db + volumes_from: + - web-data + web-data: + build: + context: . + dockerfile: Dockerfile-production + entrypoint: /bin/true + volumes: + - /opt/mean.js + - /opt/mean.js/node_modules + - /opt/mean.js/public + - /opt/mean.js/uploads + db: + image: mongo:3.2 + restart: always + volumes_from: + - db-data + db-data: + image: mongo:3.2 + volumes: + - /data/db + - /var/lib/mongodb + - /var/log/mongodb + entrypoint: /bin/true +