Quickly launch a container for building an angular-cli application. This is mainly meant for learning angular-cli and playing around with it, not developing a full-featured application.
First we'll build an image with all the angular-cli dependencies and a holding directory for your angular-cli app.
On the first container launch we'll bind-mount the apps directory to the holding directory in the container, change to the holding directory, and create your new app.
On subsequent container launches we'll start in your application directory and launch your app with angular-cli. You can send angular-cli commands to your container using docker exec
.
- In docker-compose.yml, replace "MY-APP" with the name of your app througout.
- Run
docker-compose build
. - Run
docker-compose up
. - In docker-compose.yml, comment out the line that starts with "command".
Run docker-compose up -d
.
Launch your favorite browser on your host machine and navigate to "localhost:4200".
Run docker exec -it angularplayground_angular-app_1 <your angular-cli command>
, e.g. docker exec -it angularplayground_angular-app_1 ng generate component my_great_component
.
Your app was created in the apps directory, and is mounted live to your container. Develop on your host machine in the environment of your choice. Angular will detect your changes and restart the app. Usually your browser will refresh with your changes.
Run docker-compose down
.
This angular-playground project is version controlled in git. Once you start creating your app, you might want your own version control. Without some git reconfiguration, your changes might get pushed to this repo, and not a new repo specific to your app. Here are the steps:
- Remove this repo as a git-remote by running
git remote remove origin
. - Remove the .gitignore in the apps directory. This is partly a safety measure to keep you from checking your application into my repo by mistake, and you'll want it gone once you've changed your origin and want to commit your app's code.
- If you want your project to be stored on a git server somewhere, add that server as a git remote following the instructions from the hosting provider.