Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add docker-compose start #74

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules
coverage
build
env
htmlcov
.dockerignore
Dockerfile-dev
Dockerfile-prod
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NODE_PATH=./src
15 changes: 15 additions & 0 deletions Dockerfile-dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# base image
FROM node:11.6.0-alpine

# set working directory
WORKDIR /usr/src/app

# add `/usr/src/app/node_modules/.bin` to $PATH
ENV PATH /usr/src/app/node_modules/.bin:$PATH

# install and cache app dependencies
COPY package.json /usr/src/app/package.json
RUN npm install --silent

# start app
CMD ["npm", "run", "serve"]
41 changes: 41 additions & 0 deletions Dockerfile-prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

###########
# BUILDER #
###########

# base image
FROM node:11.6.0-alpine as builder

# set working directory
WORKDIR /usr/src/app

# install app dependencies
ENV PATH /usr/src/app/node_modules/.bin:$PATH
COPY package.json /usr/src/app/package.json
RUN npm install --silent


# create build
COPY . /usr/src/app
RUN npm run build


#########
# FINAL #
#########

# base image
FROM nginx:1.15.8-alpine

# update nginx conf
RUN rm -rf /etc/nginx/conf.d
COPY conf /etc/nginx

# copy static files
COPY --from=builder /usr/src/app/dist /usr/share/nginx/html

# expose port
EXPOSE 80

# run nginx
CMD ["nginx", "-g", "daemon off;"]
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,20 @@ npm install or yarn
npm run serve or yarn (run) serve
```

## Docker 快速安装

开发环境:

```sh
docker-compose -f docker-compose-dev.yml up -d --build
```

生产环境:

```sh
docker-compose -f docker-compose-prod.yml up -d --build
```

## 下个版本开发计划

- [ ] 完成插件机制
Expand Down
12 changes: 12 additions & 0 deletions conf/conf.d/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
server {
listen 80;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
25 changes: 25 additions & 0 deletions docker-compose-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: '3.7'

services:

client:
build:
context: .
dockerfile: Dockerfile-dev
volumes:
- '../lin-cms-vue:/usr/src/app'
- '/usr/src/app/node_modules'
ports:
- 8080:8080
environment:
- NODE_ENV=development

nginx:
build:
context: ./nginx
dockerfile: Dockerfile-dev
restart: always
ports:
- 80:80
depends_on:
- client
23 changes: 23 additions & 0 deletions docker-compose-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: '3.7'

services:

client:
container_name: client
build:
context: .
dockerfile: Dockerfile-prod
args:
- NODE_ENV=production
expose:
- 80

nginx:
build:
context: ./nginx
dockerfile: Dockerfile-prod
restart: always
ports:
- 80:80
depends_on:
- client
4 changes: 4 additions & 0 deletions nginx/Dockerfile-dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM nginx:1.15.8-alpine

RUN rm /etc/nginx/conf.d/default.conf
COPY /dev.conf /etc/nginx/conf.d
4 changes: 4 additions & 0 deletions nginx/Dockerfile-prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM nginx:1.15.8-alpine

RUN rm /etc/nginx/conf.d/default.conf
COPY /prod.conf /etc/nginx/conf.d
16 changes: 16 additions & 0 deletions nginx/dev.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
server {

listen 80;

location / {
proxy_pass http://client:8080;
proxy_http_version 1.1;
proxy_redirect default;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
}
16 changes: 16 additions & 0 deletions nginx/prod.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
server {

listen 80;

location / {
proxy_pass http://client:80;
proxy_http_version 1.1;
proxy_redirect default;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
}