From 59a138f0325b3ebd4038c3f7e1737f761f6870e7 Mon Sep 17 00:00:00 2001 From: SliverHorn <503551462@qq.com> Date: Thu, 10 Sep 2020 19:15:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96docker-compose=E7=9A=84?= =?UTF-8?q?=E5=89=8D=E7=AB=AF=E9=A1=B9=E7=9B=AE=E4=B8=8D=E4=BE=9D=E8=B5=96?= =?UTF-8?q?=E4=BA=8EGin,=E4=BD=BF=E7=94=A8nginx?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .docker-compose/nginx/conf.d/my.conf | 26 +++++++++ .docker-compose/shell/server-handle.sh | 52 +++-------------- .docker-compose/shell/web-handle.sh | 10 ---- README.md | 80 ++++++++++++++++++++++++-- docker-compose.yaml | 20 ++++++- docker/docker-start.sh | 0 dockerfile_server | 40 +++---------- dockerfile_web | 20 +++++++ 8 files changed, 157 insertions(+), 91 deletions(-) create mode 100644 .docker-compose/nginx/conf.d/my.conf delete mode 100644 .docker-compose/shell/web-handle.sh mode change 100755 => 100644 docker/docker-start.sh create mode 100644 dockerfile_web diff --git a/.docker-compose/nginx/conf.d/my.conf b/.docker-compose/nginx/conf.d/my.conf new file mode 100644 index 00000000..fec3d8a1 --- /dev/null +++ b/.docker-compose/nginx/conf.d/my.conf @@ -0,0 +1,26 @@ +server { + listen 8000; + server_name localhost; + + #charset koi8-r; + #access_log logs/host.access.log main; + + location / { + root /usr/share/nginx/html; + add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0'; + try_files $uri $uri/ /index.html; + } + + location /api { + proxy_set_header Host $http_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-Proto $scheme; + rewrite ^/api/(.*)$ /$1 break; #重写 + proxy_pass http://172.25.0.4:8888; # 设置代理服务器的协议和地址 + } + + location /api/swagger/index.html { + proxy_pass http://127.0.0.1:8888/swagger/index.html; + } + } \ No newline at end of file diff --git a/.docker-compose/shell/server-handle.sh b/.docker-compose/shell/server-handle.sh index 232a1daf..934af6b5 100644 --- a/.docker-compose/shell/server-handle.sh +++ b/.docker-compose/shell/server-handle.sh @@ -1,48 +1,5 @@ #! /bin/bash -rm -f ./core/server.go -# 生成server.go文件, 添加Router.Static("/admin", "./resource/dist")这个代码 -touch ./core/server.go -filename="./core/server.go" -cat>"${filename}"<"${filename}"< Bilibili:https://www.bilibili.com/video/BV1Fg4y187Bw/ (v1.0版本视频,v2.0操作相同目录不同) - + (2)模板使用 > Bilibili:https://www.bilibili.com/video/BV16K4y1r7BD/ (v1.0版本视频,v2.0操作相同目录不同) @@ -286,7 +358,7 @@ swag init ### QQ交流群:622360840 | QQ 群(满) | -| :---: | +| :---: | | | ### 微信交流群 diff --git a/docker-compose.yaml b/docker-compose.yaml index 0968c9ce..ff4338c0 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,11 +1,25 @@ version: "3.8" services: + web: + build: + context: ./ + dockerfile: ./Dockerfile + container_name: gva-web + restart: always + ports: + - '8000:8000' + links: + - server + depends_on: + - server + command: ['nginx-debug', '-g', 'daemon off;'] + server: build: context: ./ - dockerfile: ./dockerfile_server - container_name: gva-server # 容器名 + dockerfile: ./DockerfileServer + container_name: gva-server restart: always ports: - '8888:8888' @@ -19,7 +33,7 @@ services: command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci #设置utf8字符集 restart: always ports: - - "13306:3306" # host物理直接映射端口为6606 + - "13306:3306" # host物理直接映射端口为13306 environment: MYSQL_DATABASE: 'qmPlus' # 初始化启动时要创建的数据库的名称 MYSQL_ROOT_PASSWORD: 'Aa@6447985' # root管理员用户密码 diff --git a/docker/docker-start.sh b/docker/docker-start.sh old mode 100755 new mode 100644 diff --git a/dockerfile_server b/dockerfile_server index 20bb0274..523d5a0f 100644 --- a/dockerfile_server +++ b/dockerfile_server @@ -1,20 +1,4 @@ -FROM node:12.16.1 as gva-web - -WORKDIR /gva_web/ -COPY web/ . - -RUN cat .env.production -COPY .docker-compose/shell/web-handle.sh . -RUN ls -al -RUN sh ./web-handle.sh -RUN cat .env.production -RUN rm -f web-handle.sh - -RUN npm install -g cnpm --registry=https://registry.npm.taobao.org -RUN cnpm install || npm install -RUN npm run build - -FROM golang:alpine as gva-server +FROM golang:alpine ENV GO111MODULE=on ENV GOPROXY=https://goproxy.io,direct @@ -30,25 +14,19 @@ RUN rm -f server-handle.sh RUN cat ./core/server.go RUN cat ./config.yaml -RUN go env && go list && go build -o gva-server . - +RUN go env && go build -o server . -FROM nginx:alpine -LABEL MAINTAINER="SliverHorn" -WORKDIR gva/ - -# copy web -COPY --from=gva-web /gva_web/dist ./resource/dist -# copy server -COPY --from=gva-server /go/src/gin-vue-admin/gva-server ./ -COPY --from=gva-server /go/src/gin-vue-admin/config.yaml ./ -COPY --from=gva-server /go/src/gin-vue-admin/resource ./resource +FROM alpine:latest +LABEL MAINTAINER="SliverHorn@sliver_horn@qq.com" +WORKDIR /go/src/gin-vue-admin -EXPOSE 8888 +COPY --from=0 /go/src/gin-vue-admin/server ./ +COPY --from=0 /go/src/gin-vue-admin/config.yaml ./ +COPY --from=0 /go/src/gin-vue-admin/resource ./resource -ENTRYPOINT ./gva-server +ENTRYPOINT ./server # 根据Dockerfile生成Docker镜像 diff --git a/dockerfile_web b/dockerfile_web new file mode 100644 index 00000000..eaf6e223 --- /dev/null +++ b/dockerfile_web @@ -0,0 +1,20 @@ +FROM node:12.16.1 + +WORKDIR /gva_web/ +COPY web/ . + +RUN npm install -g cnpm --registry=https://registry.npm.taobao.org +RUN cnpm install || npm install +RUN npm run build + +FROM nginx:alpine +LABEL MAINTAINER="SliverHorn@sliver_horn@qq.com" + +COPY .docker-compose/nginx/conf.d/my.conf /etc/nginx/conf.d/my.conf +COPY --from=0 /gva_web/dist /usr/share/nginx/html +RUN cat /etc/nginx/nginx.conf +RUN cat /etc/nginx/conf.d/my.conf +RUN ls -al /usr/share/nginx/html +CMD ls -al /usr/share/nginx/html + +CMD ['nginx-debug', '-g', 'daemon off;'] \ No newline at end of file -- GitLab