Skip to content

Commit 1c11f99

Browse files
committed
dokerfile
1 parent 335162a commit 1c11f99

File tree

6 files changed

+12045
-51
lines changed

6 files changed

+12045
-51
lines changed

Dockerfile

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,38 @@
1-
# Usage:
1+
# https://nodejs.org/en/docs/guides/nodejs-docker-webapp/
2+
# https://medium.com/@VincentSchoener/development-of-nodejs-application-with-docker-and-typescript-part-2-4dd51c1e7766
23
#
3-
# Build image:
4-
# docker build -t code-editor .
4+
# Builder stage.
5+
# This state compile our TypeScript to get the JavaScript code
56
#
6-
# Run image (on localhost:8080):
7-
# docker run --name text-compare -p 8080:80 text-compare
8-
#
9-
# Run image as virtual host (read more: https://github.com/jwilder/nginx-proxy):
10-
# docker run -e VIRTUAL_HOST=text-compare.your-domain.com --name text-compare text-compare
7+
#FROM node:15.12.0 AS builder
118

12-
# Stage 1, based on Node.js, to build and compile Angular
9+
#WORKDIR /usr/src/app
1310

14-
FROM node:9.4.0-alpine as builder
11+
#COPY package*.json ./
12+
#COPY webpack*.js ./
13+
#COPY .babelrc ./
14+
#COPY ./src ./src
15+
#COPY ./public ./public
16+
#RUN npm ci --quiet && npm run build
1517

16-
COPY package.json ./
18+
#
19+
# Production stage.
20+
# This state compile get back the JavaScript code from builder stage
21+
# It will also install the production package only
22+
#
23+
FROM node:15.12.0-alpine
1724

18-
## Storing node modules on a separate layer will prevent unnecessary npm installs at each build
19-
RUN npm i && mkdir /ng-app && mv ./node_modules ./ng-app
25+
WORKDIR /app
2026

21-
WORKDIR /ng-app
27+
# environment variables
28+
ENV PORT=80
2229

2330
COPY . .
31+
#COPY ./src ./build/src
32+
#RUN npm ci --quiet --only=production
2433

25-
RUN npm run build:aot:prod
26-
27-
# Stage 2, based on Nginx, to have only the compiled app, ready for production with Nginx
28-
29-
FROM nginx:1.13.12-alpine
30-
31-
COPY ./config/nginx-custom.conf /etc/nginx/conf.d/default.conf
32-
33-
## Remove default nginx website
34-
RUN rm -rf /usr/share/nginx/html/*
35-
36-
## From ‘builder’ stage copy over the artifacts in dist folder to default nginx public folder
37-
COPY --from=builder /ng-app/dist /usr/share/nginx/html
34+
# We just need the build to execute the command
35+
#COPY --from=builder /usr/src/app ./build
3836

39-
CMD ["nginx", "-g", "daemon off;"]
37+
#CMD [ "node" "/build/src/server/index.js" ]
38+
CMD [ "node", "server.js" ]

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,19 @@ Read portfolio [Code Editor(React)](https://jojozhuang.github.io/project/code-ed
4444

4545
# Tutorial
4646
Read tutorial [Building Online Code Editor with React and Express](https://jojozhuang.github.io/tutorial/building-online-code-editor-with-react-and-express) to learn how this online code editor is built.
47+
48+
49+
# Docker
50+
Build for production. All the compiled html files and js files will be generated in `dist`.
51+
```sh
52+
npm run build
53+
```
54+
Create image with nginx.
55+
```sh
56+
docker build -t jojozhuang/code-editor .
57+
```
58+
Create container.
59+
```sh
60+
docker run --name code-editor -p 9010:80 -d jojozhuang/code-editor
61+
```
62+
Access http://192.168.0.2:9010/ in browser.

0 commit comments

Comments
 (0)