Skip to content

Commit

Permalink
perf(docker): build app for production and dockerize
Browse files Browse the repository at this point in the history
Change Dockerfile to build app for production and server with nginx, rather than running the dev
server. Create an nginx config to serve the app. Use .dockerignore to ensure nothing sensitive or
wasteful is built into the image.  Update  .gitignore to prevent commit of build files. Update
readme with appropriate nginx port.

closes #29
  • Loading branch information
JacobTheEldest committed May 24, 2023
1 parent 597acce commit 6f76ca9
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.git
.DS_Store
.env
node_modules
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

# production
/build
/dist

# misc
.DS_Store
Expand Down
15 changes: 7 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
FROM node:lts-alpine3.17
FROM node:current-alpine as build

WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install

RUN npm clean-install
COPY . .
RUN npm run build

EXPOSE 3000

CMD [ "npm", "run", "dev" ]
FROM nginx:mainline-alpine
EXPOSE 80
COPY ./docker/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf
COPY --from=build /usr/src/app/dist /usr/share/nginx/html
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,6 @@ services:
image: jacobtheeldest/minesweeper:latest
restart: unless-stopped
ports:
- "3000:3000"
- "80:80"
```
9 changes: 9 additions & 0 deletions docker/nginx/conf.d/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
server {
listen 80;
root /usr/share/nginx/html;
index index.html;

location / {
try_files $uri $uri/ /index.html;
}
}

0 comments on commit 6f76ca9

Please sign in to comment.