Creating angular 17 project without installing anything in host machine with the help of docker.
docker-compose run --rm ng new --directory ./ --skip-install
-
Give your desired name for the project when prompted
-
Abort (CTR + C) if node package is getting installed
-
If
node_modules
folder was created, the error like the below screenshot will be thrown when trying to runng serve
. So delete it, if it got created.
- Command to delete node_modules in Linux and wsl
rm -rf angular/node_modules
- Command to delete node_modules in powershell
Remove-Item angular/node_modules -Recurse -Force
- Command to delete node_modules in command prompt
rmdir angular\node_modules
- Add
"ng-start": "ng serve --host 0.0.0.0",
toscript
property inpackage.json
file
- Spin-up the
vite
server
docker-compose up -d --build server
-d
to run in detached mode.
-
Copy the
package-lock.json
to host machine- Check running conatiner by
docker ps
and consider this last container name isangular_with_docker_server_1
- Check running conatiner by
docker cp angular_with_docker_server_1:/app/package-lock.json angular
-
Point your browser to
http://localhost:4201/
-
After finished working,
docker-compose down
to remove named volumes while removing container,
docker-compose down -v
docker-compose run --rm ng g c pages/home
- we can see example with
ng add @angular/pwa
. Other packages also uses the same way to be added!
docker-compose run --rm ng add @angular/pwa
- Run
npm install
as below always
docker-compose run --rm npm install
- Installing
lodash
follows below:
docker-compose run --rm npm install --save lodash
docker-compose run --rm npm install --save-dev @types/lodash
Remove node_modules
after finishing it all.
docker-compose up --build test
-
Point your browser to
http://localhost:4203/
-
Remove the container
docker-compose down
- Building angular files
docker-compose run --rm build run build
- Running express server
docker-compose run --rm build run serve:ssr:my_angular_play
- You can try any
script
inpackage.json
afternpm
withdocker-compose run --rm build run
- Navigate to the folder where
angular.dockerfile
exists, then execute the below command
- Building the image for Angular 17
docker build . -t actionanand/ng-create:17 -f angular.dockerfile
- Pushing the Image
docker push actionanand/ng-create:17
- Pull Angular 17
docker pull actionanand/ng-create:17
- Creating new angular project
docker run --rm -it --name ng-create -v "folder_path:/app" actionanand/ng-create:17 new
In mac, linux or wsl2
docker run --rm -it --name ng-create -v $(pwd):/app actionanand/ng-create:17 new
In windows,
docker run --rm -it --name ng-create -v "D:\AR_extra\rnd\docker\test:/app" actionanand/ng-create:17 new
- creating new Angular project in the current folder
docker run --rm -it --name ng-create -v $(pwd):/app actionanand/ng-create:17 new --directory .
- Creating
home
component under the folderpages
docker run --rm -it --name ng-create -v $(pwd):/app actionanand/ng-create:17 g c pages/home
- we can see example with
ng add @angular/pwa
. Other packages also uses the same way to be added!
docker run --rm -it --name ng-create -v $(pwd):/app actionanand/ng-create:17 add @angular/pwa
docker container prune
- to remove all stopped containersdocker system prune
- to remove all stopped images. This command will remove all stopped containers, networks, and dangling images- If you want to remove all images, not just the dangling ones, you can add the '-a' option to the command, like so:
docker system prune -a
docker volume prune
- to remove unused volumes