Skip to content

Commit 7d796b2

Browse files
Add docker compose to run the app in docker + db
1 parent 0101e52 commit 7d796b2

File tree

5 files changed

+29
-6
lines changed

5 files changed

+29
-6
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# See http://help.github.com/ignore-files/ for more about ignoring files.
22

33
# compiled output
4+
/data
45
/dist
56
/tmp
67
/out-tsc

Dockerfile

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
FROM node:12.18.2
22

33
WORKDIR /usr/src/app
4-
COPY package.json .
5-
RUN npm i -g @angular/cli@~10.0.1 typescript@~3.9.6
6-
RUN npm i
4+
COPY package*.json ./
5+
RUN npm ci
76
COPY . .
8-
RUN tsc -p ./server && ng build --aot --prod
9-
10-
CMD [ "npm", "start" ]
7+
ENV MONGODB_URI mongodb://mongo:27017/angularfullstack
8+
RUN npm run predev && npm run buildprod
9+
EXPOSE 3000
10+
CMD [ "npm", "start" ]

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ A window will automatically open at [localhost:4200](http://localhost:4200). Ang
3131
### Production mode
3232
`npm run prod`: run the project with a production bundle and AOT compilation listening at [localhost:3000](http://localhost:3000)
3333

34+
### Docker
35+
1. `docker-compose up`
36+
2. Go to [localhost:3000](http://localhost:3000)
37+
3438
## Preview
3539
![Preview](https://raw.githubusercontent.com/DavideViolante/Angular2-Full-Stack/master/demo.gif "Preview")
3640

docker-compose.yml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
version: "2"
2+
services:
3+
app:
4+
container_name: afs
5+
restart: always
6+
build: .
7+
ports:
8+
- "3000:3000"
9+
links:
10+
- mongo
11+
mongo:
12+
container_name: mongo
13+
image: mongo
14+
volumes:
15+
- ./data:/data/db
16+
ports:
17+
- "27017:27017"

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"scripts": {
1212
"ng": "ng",
1313
"build": "ng build",
14+
"buildprod": "ng build --aot --prod",
1415
"start": "node dist/server/app.js",
1516
"predev": "tsc -p server",
1617
"dev": "concurrently \"mongod\" \"ng serve --proxy-config proxy.conf.json --open\" \"tsc -w -p server\" \"nodemon dist/server/app.js\"",

0 commit comments

Comments
 (0)