Skip to content

Instantly share code, notes, and snippets.

@nimatrazmjo
Created January 29, 2019 10:32
Show Gist options
  • Save nimatrazmjo/3f4927ccb973ba1fd292d56c33fca81e to your computer and use it in GitHub Desktop.
Save nimatrazmjo/3f4927ccb973ba1fd292d56c33fca81e to your computer and use it in GitHub Desktop.
Checking for standard way of using docker and docker compose for MEAN stack to development and production
version: '3'
services:
jobsaf-server:
build:
context: .
dockerfile: Dockerfile.production
container_name: jobsaf-server
command: npm start
ports:
- "3000:3000"
- "5858:5858"
- "35729:35729"
- "6379:6379"
environment:
- NODE_ENV=production
networks:
- front-tier
- back-tier
depends_on:
- "redis"
- "mongo"
links:
- mongo
- redis
volumes:
- ./server:/var/www/app/jobsaf-website/server
nginx:
image: nginx:stable
depends_on:
- jobsaf-server
links:
- jobsaf-server
volumes:
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
ports:
- "0.0.0.0:80:80"
mongo:
image: mongo:latest
container_name: mongo
volumes:
- "db-data:/data/db"
environment:
- MONGO_INITDB_ROOT_USERNAME=${DB_USER}
- MONGO_INITDB_ROOT_PASSWORD=${DB_PASS}
- MONGO_INITDB_DATABASE=admin
ports:
- "0.0.0.0:27017:27017"
networks:
- back-tier
redis:
image: redis
container_name: redis
networks:
- back-tier
volumes:
db-data:
# - /data/db
networks:
front-tier:
back-tier:
version: '3'
services:
jobsaf-website:
build: .
container_name: jobsaf-website
command: ng serve --host 0.0.0.0 --poll=200
ports:
- "4200:4200"
- "49153:49153"
environment:
- NODE_ENV=development
networks:
- front-tier
- back-tier
volumes:
- ./src:/var/www/app/jobsaf-website/src
- /var/www/app/jobsaf-website/node_modules
- /var/www/app/jobsaf-website/public
- /var/www/app/jobsaf-website/uploads
links:
- jobsaf-server
jobsaf-server:
build: .
container_name: jobsaf-server
command: npm start
ports:
- "3000:3000"
- "5858:5858"
- "35729:35729"
- "6379:6379"
environment:
- NODE_ENV=development
networks:
- front-tier
- back-tier
depends_on:
- "redis"
- "mongo"
links:
- mongo
- redis
volumes:
- ./server:/var/www/app/jobsaf-website/server
- /var/www/app/jobsaf-website/node_modules
- /var/www/app/jobsaf-website/public
- /var/www/app/jobsaf-website/uploads
mongo:
image: mongo:latest
container_name: mongo
volumes:
- "db-data:/data/db"
ports:
- "0.0.0.0:27017:27017"
networks:
- back-tier
# command: mongod
redis:
image: redis
container_name: redis
networks:
- back-tier
volumes:
db-data:
networks:
front-tier:
back-tier:
FROM ubuntu:18.04
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
RUN apt-get update && apt-get upgrade -y \
&& apt-get install -y --no-install-recommends \
build-essential \
ca-certificates \
gcc \
git \
libpq-dev \
make \
python-pip \
python2.7 \
python2.7-dev \
apt-transport-https \
curl \
g++ \
sudo \
wget \
bzip2 \
chrpath \
libssl-dev \
libxft-dev \
libfreetype6 \
libfreetype6-dev \
libfontconfig1 \
libfontconfig1-dev \
libfontconfig \
poppler-utils \
imagemagick \
&& apt-get clean \
&& rm -rf /tmp/* /var/lib/apt/lists/* \
&& apt-get -y autoclean
RUN apt-get update && apt-get install -y --no-install-recommends software-properties-common && add-apt-repository ppa:malteworld/ppa && apt update && apt install -y --no-install-recommends pdftk \
&& apt-get clean \
&& rm -rf /tmp/* /var/lib/apt/lists/* \
&& apt-get -y autoclean
ENV NVM_DIR /usr/local/nvm
ENV NODE_VERSION 10.6.0
# Install nvm with node and npm
RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.29.0/install.sh | bash \
&& source $NVM_DIR/nvm.sh \
&& nvm install $NODE_VERSION \
&& nvm alias default $NODE_VERSION \
&& nvm use default
# Set up our PATH correctly so we don't have to long-reference npm, node, &c.
ENV NODE_PATH $NVM_DIR/versions/node/v$NODE_VERSION/lib/node_modules
ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH
# Set the work directory
RUN mkdir -p /var/www/app/jobsaf-website
RUN mkdir /data
RUN mkdir /data/db
WORKDIR /var/www/app/jobsaf-website
RUN npm install -g node-gyp @angular/[email protected] nodemon request
# Add our package.json and install *before* adding our application files
COPY package.json ./
# RUN npm install --force
RUN npm install --force
RUN npm rebuild node-sass
# Add application files
ADD . .
EXPOSE 3000 5858 4200 35729 27017 6379 49153
FROM ubuntu:18.04
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
RUN apt-get update && apt-get upgrade -y \
&& apt-get install -y --no-install-recommends \
build-essential \
ca-certificates \
gcc \
git \
libpq-dev \
make \
python-pip \
python2.7 \
python2.7-dev \
apt-transport-https \
curl \
g++ \
sudo \
wget \
bzip2 \
chrpath \
libssl-dev \
libxft-dev \
libfreetype6 \
libfreetype6-dev \
libfontconfig1 \
libfontconfig1-dev \
libfontconfig \
poppler-utils \
imagemagick \
&& apt-get clean \
&& rm -rf /tmp/* /var/lib/apt/lists/* \
&& apt-get -y autoclean
RUN apt-get update && apt-get install -y --no-install-recommends software-properties-common && add-apt-repository ppa:malteworld/ppa && apt update && apt install -y --no-install-recommends pdftk \
&& apt-get clean \
&& rm -rf /tmp/* /var/lib/apt/lists/* \
&& apt-get -y autoclean
ENV NVM_DIR /usr/local/nvm
ENV NODE_VERSION 10.6.0
# Install nvm with node and npm
RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.29.0/install.sh | bash \
&& source $NVM_DIR/nvm.sh \
&& nvm install $NODE_VERSION \
&& nvm alias default $NODE_VERSION \
&& nvm use default
# Set up our PATH correctly so we don't have to long-reference npm, node, &c.
ENV NODE_PATH $NVM_DIR/versions/node/v$NODE_VERSION/lib/node_modules
ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH
# Set the work directory
# RUN mkdir -p /var/www/app/jobsaf-website
RUN mkdir /data
RUN mkdir /data/db
WORKDIR /var/www/app/jobsaf-website
RUN npm install -g @angular/[email protected] nodemon pm2@latest request
# Add our package.json and install *before* adding our application files
COPY package.json ./
# RUN npm install --force
RUN npm install --force
RUN npm rebuild node-sass
# Add application files
ADD . .
RUN npm run build:prod
RUN pm2 start ecosystem.config.js
EXPOSE 3000 5858 4200 35729 27017 6379
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment