Docker 启动前后端脚本
后端
docker 提前运行 consul,mongo,redis
进入到 Jar所在的文件夹(文件夹下只有一个Jar!)
新建 start.sh
CMD jar_name=$(ls -1 -F *.jar) && \
java -Xms450m -Xmx450m \
-XX:+UseContainerSupport -XX:MaxRAMPercentage=80 -XX:MaxMetaspaceSize=178m -XX:MetaspaceSize=178m -Xss512k ${JAVA_OPTS} \
-Dlog4j2.formatMsgNoLookups=true \
-Dspring.cloud.bootstrap.enabled=true \
-Dreactor.netty.pool.leasingStrategy=lifo \
-Dloader.path=lib \
-jar $jar_name \
--spring.main.allow-bean-definition-overriding=true \
--spring.main.allow-circular-references=true \
--spring.profiles.active=consul,yuxh,amy $*
执行Docker (暴露端口,是给前端调用联调用!)
docker run -d --name gateway -v "$PWD":/app -w /app -p 8083:8083 --link consul:consul --link mongo:mongo --link redis:redis openjdk:17 /bin/bash /app/start.sh
前端
/vue/nginx.cnf
server {
listen 80;
listen [::]:80;
server_name _;
#access_log /var/log/nginx/host.access.log main;
absolute_redirect off;
index index.html;
location /api/ {
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Origin' "$http_origin";
add_header 'Access-Control-Allow-Methods' '$http_access_control_request_method';
add_header 'Access-Control-Allow-Headers' '$http_access_control_request_headers';
add_header 'Access-Control-Expose-Headers' '$http_access_control_request_headers';
add_header 'Access-Control-Max-Age' '2592000';
add_header 'Content-Length' 0;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Access-Control-Allow-Headers' 'Authorization';
return 204;
}
proxy_pass http://mp-gateway-api:8083/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /{虚拟目录} {
alias /vue/;
try_files $uri $uri/ /index.html =404;
}
}
cp /vue/nginx.cnf /vue/{应用名}/nginx.cnf
cd /vue/{应用名}
修改 nginx.cnf 中的 虚拟目录
docker run -d -p 8010:80 --name {应用名} --link mp-gateway-api:mp-gateway-api -v "$PWD"/nginx.conf:/etc/nginx/conf.d/default.conf -v "$PWD"/dist:/vue/ nginx
作者:NewSea 出处:http://newsea.cnblogs.com/
QQ,MSN:iamnewsea@hotmail.com 如无特别标记说明,均为NewSea原创,版权私有,翻载必纠。欢迎交流,转载,但要在页面明显位置给出原文连接。谢谢。 |