Git Product home page Git Product logo

angular-cli-docker's Introduction

angular-cli in a Container

Although it is not really difficult, it took me quite some time to use angular-cli on my Mac in a docker container.

This project contains my initial thoughts for easily creating, developing and running an Angular 2 App with docker container.

General Idea

This project provides 2 Dockerfiles. The first Dockerfile is contained in root and responsible for setting up an image containing a specific version (currently this is v1.0.0-beta.28.3) of angular-cli. It also prepares a non-root user. However, this shouldn't be used until the initial project is created with ng new. Root permissions are required to create the project.

Once the initial project is created with base Dockerfile, both files from docker-app-seed can be copied into the newly created Angular 2 App. These files allow installing all dependencies inside a container and running project specific commands offered by angular-cli (e.g. ng serve).

Creating a new Angular 2 App

You simply copy the Dockerfile and call docker build -t angular-cli:1.0.0-beta.28.3 . in the same folder. This will create an image containing the appropriate angular-cli version.

This new image can now be used to create the basis for your new Angular 2 App. Simply call

docker run -it --rm --name create-angular-project -v "$PWD":/home/app angular-cli:1.0.0-beta.28.3 ng new -sn APP_NAME

Obviously you should replace APP_NAME with the name of the app you like to build.

This finally creates your new app in a subfolder. With the -sn option we skip the installation of the complete tooling. This is important, because we don't want to have all the node modules installed in the bind-mounted host folder.

Instead we create another image, which stores the node modules on a separate volume. See this article for an excellent discussion. The next section shows you how to actually build the new image.

Building a new image for development

Once the app is created with ng new we can switch into the folder and build an image with all dependencies. First you need to copy the Dockerfile as well as the docker-compose.yml file from the docker-app-seed folder into your newly created application folder. Once you copied the files you might want to adapt the APP_NAME in the Dockerfile and the service name in the docker-compose.yml.

Finally you can build the image, which compiles and serves your app with:

docker-compose build

Serving your new App

Finally you can call docker-compose up to serve your new app. It will be accessible on http://localhost:4200/. You can see that everything works as expected, if a website with "app works" is shown in your browser.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.