DZone
Cloud Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Cloud Zone > Deploying Angular 2 Apps to Bluemix

Deploying Angular 2 Apps to Bluemix

In this post we take a look at how to deploy your Angular 2 app as a Docker container to IBM's Bluemix and the light configuration you need to do to make it work.

Niklas Heidloff user avatar by
Niklas Heidloff
CORE ·
Apr. 16, 17 · Cloud Zone · Tutorial
Like (3)
Save
Tweet
6.41K Views

Join the DZone community and get the full member experience.

Join For Free

over the last few months, i’ve done quite a lot of angular 2 development (now angular 4). below is a description how to create a new angular app and deploy it as a docker container to bluemix in just a few minutes.

in order to create a new angular app, you can use the angular cli .

npm install -g @angular/cli
ng new angular-app
cd angular-app
ng build --prod


there are several ways to deploy angular apps to bluemix. for example, you can build a simple node.js web server to host the files. or you can leverage existing http servers like nginx . you can use nginx in the cloud foundry staticfile-buildpack or in docker. since i experienced issues with the cloud foundry buildpack (i couldn’t enforce https), the following steps show how to use docker.

copy the following lines in the file ‘dockerfile’ in your project’s root directory.

from nginx:latest
copy nginx.conf /etc/nginx/conf.d/default.conf
copy dist /usr/share/nginx/html


copy the following lines into ‘nginx.conf’. there are many other features nginx provides that can be configured in this file, e.g. gzip settings and caching.

server {
    listen 80;
    charset utf-8;
    sendfile on;
    root /usr/share/nginx/html;
  
    location / {
        expires -1;
        add_header pragma "no-cache";
        add_header cache-control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";
 
        try_files $uri $uri/ /index.html = 404;
    }
 
    location /api/v1/namespaces/ {
        proxy_pass https://openwhisk.ng.bluemix.net; 
    }    
}


the location ‘/api/v1/namespaces/’ is an example how to invoke a rest api from your angular app, in this case, to invoke an openwhisk action.

next, the docker container needs to be built.

docker build -t angular-app .
docker tag angular-app registry.ng.bluemix.net/nheidloff/angular-app
docker push registry.ng.bluemix.net/nheidloff/angular-app


there are different ways to run the container on bluemix — for example, as scalable container group or in a kubernetes cluster. for testing purposes, you can also run the container as single instance with a public ip address:

bx ic run --name angular-app -p 80 -m 128 registry.ng.bluemix.net/nheidloff/angular-app
bx ic ips
bx ic ip-bind 169.46.26.176 angular-app
bx ic inspect angular-app


this is the file structure of the angular project.

angular2bluemix

AngularJS app Docker (software) Bluemix Kubernetes

Published at DZone with permission of Niklas Heidloff, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Pattern Matching for Switch
  • Exhaustive JUNIT5 Testing with Combinations, Permutations, and Products
  • How to Translate Value to Executives Using an Outcome-Driven Mindset
  • RSA Conference Recap for Developers

Comments

Cloud Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo