Skip to main content

Creating MEAN app with Angular 2 and Docker Compose


Docker allows us to run applications inside containers. These containers in most cases communicate with each other.
Docker containers wrap a piece of software in a complete filesystem that contains everything needed to run: code, runtime, system tools, system libraries – anything that can be installed on a server. This guarantees that the software will always run the same, regardless of its environment.

Why Use Docker

  1. Docker images usually include only what your application needs to run. As a result, you don't have to worry about having a whole operating system with things you will never user. This results in smaller images of your application.
  2. Platform Indipendent - I bet you've heard of the phrase 'It worked on my machine, and doesn't work on the server'. With Docker, all either environments need to have is the Docker Engine, or the Docker Daemon, and when we have a successful build of our image, it should run anywhere.
  3. Once you have an image of your application built, you can easily share the image to anyone who wants to run your application. They need not worry about dependencies, or setting up their individual environments. All they need to have is Docker Engine installed.
  4. Isolation - You'll see from the article that I try to separate the individual apps to become indipendent, and only point to each other. The reason behind this is that each part of our entire application should be somewhat indipendent, and scalable on it's own. Docker in this instance would make scaling these individual parts as easy as spinning up another instance of their images. This concept of building isolated, indipendenlty scalable parts of an entire system is what is called Microservices Approach.You can read more about it in Introduction to Microservices
  5. Docker images usually have tags, referring to their versions. This means you can have versioned builds of your image, enabling you to roll back to a previous version should something unexpected break
$ docker  -v
Docker version 1.12.3, build 6b644ec
npm install -g angular-cli

mkdir mean-docker

mkdir angular-client

cd angular-client

ng init

run: ng serve (application runs on http://localhost:4200)

create Dockerfile inside angular-client

# Create image based on the official Node 6 image from dockerhub
FROM node:6

# Create a directory where our app will be placed
RUN mkdir -p /usr/src/app

# Change directory so that our commands run inside this new directory
WORKDIR /usr/src/app

# Copy dependency definitions
COPY package.json /usr/src/app

# Install dependecies
RUN npm install

# Get all the code needed to run the app
COPY . /usr/src/app

# Expose the port the app runs in
EXPOSE 4200

# Serve the app
CMD ["npm", "start"]

create dockerignore

node_modules/

in package.json add these 

{
 ...
  "scripts": {
    "start": "ng serve -H 0.0.0.0",
    ...
  },
  ...
}
docker build -t <image_tag>:<tag> <directory_with_Dockerfile>
$ cd angular-client
$ docker build -t angular-client:dev .
docker run -d --ndocker run -d --name angular-client -p 4200:4200 angular-client:dev
8310253fe80373627b2c274c5a9de930dc7559b3dc8eef4abe4cb09aa1828a22ame <container_name> -p <host-port:exposed-port>  <image-name>
docker stop angular-client

#PART 2 COMING SOON 

Comments

Popular posts from this blog

Learn Nodejs

My favorite resource is "nodeschool.io!" "Install these choose-your-own-adventure style lessons and learn how to use node.js, npm and other related tools by writing code to solve realistic problems. The lessons run in your terminal and work on Windows, Mac and Linux."   Tutorials Hello World Hello World Web Server Node.js guide Build a blog with Node.js, express and mongodb Node.Js Tutorials At Project 70 Node.js for Beginners Learn Node.js Completely and with Confidence Videos Node tuts Introduction to Node.js with Ryan Dahl Node.js: Asynchronous Purity Leads to Faster Development Parallel Programming with Node.js Server-side JavaScript with Node, Connect & Express Node.js First Look Node.js with MongoDB Ryan Dahl's Google Tech Talk Screencasts Learn All The Nodes NodeTuts NodeCasts Books " The Node Beginner Book Mastering Node.js Up and Running with Node.js Node.js in Action Smashing Node.js: JavaScript Ev...
If you want lists, for back-end languages (in order of my ability to recall): If you want lists, for back-end languages (in order of my ability to recall): Java (and other JVM languages like Scala, Groovy, Clojure) PHP .NET (C#, VB) Ruby Python Perl Javascript (Node JS) Actionscript (Flash Media Server) CoffeeScript C (CGI) Erlang oh, and SQL for db queries For browser-based front-end languages, you're somewhat limited in what the browser can support (excluding launching out-of-browser applications). We could talk about: HTML Javascript CSS Actionscript CoffeeScript (compiled to Javascript) XML-based languages (X3D, SMIL, SVG, DITA, some interpreted by the browser, others transformed using XSL) VBScript Silverlight Java (applets) For native PC desktop front-ends, most popular front-end languages would probably be (I'm guessing, in no order): Visual Basic 6 (from my experience with big enterprises, I bet a lot of those are still out there, just like Windows Vista) .NET Jav...