sHamann
sHamann

Reputation: 799

Docker or Docker for AWS and Deployment on AWS EC2

2 Questions here.

Im trying to figure out what is the main difference between the normal Docker and Docker for AWS.

For my project i will run a GUI coded in Angular 2, packed in a Docker Container on an AWS EC2.

1) Should i use Docker for AWS for my purpose?

2) Is it possible that Docker can [1]get my Code from an GITHUB repository and [2]build it when i run docker?

3) What is the Best way to deploy an Docker Container on AWS? is there a guide to follow or some best practise examples?

Thank you in advance!

Upvotes: 2

Views: 1490

Answers (2)

Adiii
Adiii

Reputation: 60144

As @Rawkode explain everything well. I will just add something to your last point. For running docker based application using ec2 instance you can use

Deploy Docker Containers on Amazon EC2 Container Service (Amazon ECS)

Amazon EC2 Container Service (Amazon ECS) is the Amazon Web Service you use to run Docker applications on a scalable cluster.

You can run your angular app using docker. as you mention in a comment that you can use ng build --prod. Which build and create dist folder for you.Here how I deploy angular docker based application in AWS.

first, create an express server which will serve your static file.

   var express =     require('express');
   var path = require('path');
   var router = express.Router();
   var app = express();
   // serve angular front end files from root path
   app.use('/', express.static('dist', {
       redirect: false
   }));
   // rewrite virtual urls to angular app to enable refreshing of internal 
   pages
   app.get('*', function(req, res, next) {
       res.sendFile(path.resolve('dist/index.html'));
   });

   app.listen(3000, function(req, res) {
       console.log("start");
   })

so this will serve your angular static file and S3 you will face the error on refresh which can be resolved using re-write rule. create your docker file for express and express will deal with static file

    FROM alpine
RUN apk update && apk upgrade
RUN apk add nodejs
RUN mkdir -p /app
ADD app/package.json /app
WORKDIR /app/
ENV HOME /app
ENV NODE_ENV development
RUN npm install
ADD app /app
EXPOSE 3000
CMD npm start

inside app folder where express server file, place dist folder in the same directory.

now for deploy your docker based application visit this link

https://aws.amazon.com/getting-started/tutorials/deploy-docker-containers/

Best Practices for Hosting Web Applications on AWS

This above I just tried to explain how to run the angular application on AWS ECS and you can make it more good by running multiple copies of same task and configure load balancer.

As for best practices is concern for web application

For static Application

enter image description here enter image description here enter image description here

for more detail best-practices-for-hosting-web-applications-on-aws

Docker and AWS have teamed up to make it easier than ever to deploy an enterprise Containers as a Service (CaaS) Docker environment on Amazon's EC2 infrastructure. Running Docker Datacenter on AWS gives developers and IT operations a highly reliable, low-cost way to deploy production-ready workloads in a single click.

https://www.docker.com/aws

secrets-for-amazon-ec2-container-service

aws-for-startups-architectural-best-practices-automating-your-infrastructure

Upvotes: 2

Rawkode
Rawkode

Reputation: 22592

1) Should i use Docker for AWS for my purpose?

Docker for AWS provides self-healing infrastructure through CloudFormation. If you need auto-scaling for your application, then this is a good route to take. However, the cost will add up.

2) Is it possible that Docker can [1]get my Code from an GITHUB repository and [2]build it when i run docker?

Using GitHub web-hooks / integrations, you can have your image built for you, through Jenkins / Travis / ANOther CI tool. This can publish an image to the Docker Hub, or a self-hosted / third party registry.

3) What is the Best way to deploy an Docker Container on AWS? is there a guide to follow or some best practise examples?

Every use-case is different. Is this for testing? demos? production? Too many factors to tackle this I'm afraid.

Edit:

3) It is for Demos porpuse at the moment

I'd just spin up a single EC2 instance and install the docker-engine and use that

Upvotes: 2

Related Questions