I've recently learned how to use Docker and am trying to containerize an Angular project that I've been working on.
The project's package.json
is as following:
{
"name": "argon-dashboard-angular",
"version": "1.0.1",
"scripts": {
"ng": "ng",
"start": "ng serve --port 8080",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"install:clean": "rm -rf node_modules/ && rm -rf package-lock.json && npm install && npm start"
},
"private": true,
"dependencies": {
"@angular/animations": "7.2.4",
"@angular/common": "7.2.4",
"@angular/compiler": "7.2.4",
"@angular/core": "7.2.4",
"@angular/forms": "7.2.4",
"@angular/http": "7.2.4",
"@angular/platform-browser": "7.2.4",
"@angular/platform-browser-dynamic": "7.2.4",
"@angular/router": "7.2.4",
"@ng-bootstrap/ng-bootstrap": "4.0.1",
"bootstrap": "4.1.3",
"chart.js": "2.7.3",
"clipboard": "2.0.4",
"core-js": "2.6.4",
"ngx-clipboard": "11.1.9",
"ngx-toastr": "9.1.2",
"nouislider": "13.1.1",
"rxjs": "6.4.0",
"zone.js": "0.8.29"
},
"devDependencies": {
"@angular-devkit/build-angular": "0.13.1",
"@angular/cli": "7.3.1",
"@angular/compiler-cli": "7.2.4",
"@angular/language-service": "7.2.4",
"@types/jasmine": "3.3.8",
"@types/jasminewd2": "2.0.6",
"@types/node": "11.9.0",
"codelyzer": "4.5.0",
"jasmine-core": "3.3.0",
"jasmine-spec-reporter": "4.2.1",
"karma": "4.0.0",
"karma-chrome-launcher": "2.2.0",
"karma-coverage-istanbul-reporter": "2.0.4",
"karma-jasmine": "2.0.1",
"karma-jasmine-html-reporter": "1.4.0",
"protractor": "5.4.2",
"ts-node": "8.0.2",
"tslint": "5.12.1",
"typescript": "3.2.4"
}
}
My Dockerfile
is as following:
FROM node:10.18.0-alpine AS build
WORKDIR /usr/src/app
COPY package.json ./
RUN npm install
COPY . .
CMD ["npm","start"]
EXPOSE 8080
I build from the image and run my container:
docker build .
docker run <container-id>
Once the container is running, I tried to access http://localhost:8080 , but the browser reads "localhost refused to connect".
Also, my Docker Desktop app shows these buttons next to my container:
Usually there would be another button to the left that opens the container in my browser at its port.
Also, after looking through some tutorials, I noticed that many suggested using an Nginx Docker image to serve my web app. Is this necessary? Why can't I serve my app through ng serve
?