【Docker】Docker Compose启动一个示例项目
·
后端Spring boot + 前端Vue
文件目录
project #项目目录
├─ docker-compose.yml #docker-compose配置文件
├─ frontend #前端目录
| ├─ nginx.conf #nginx配置
| ├─ dist #前端打包文件
├─ backend
| ├─ app.jar #后端打包jar
| ├─ config #后端配置文件
| | └ application.yml
Docker Compose配置
# docker-compose.yml
# 配置版本
version: '3.5'
# network
networks:
net:
# 创建network的名字
name: test_net
# 使用bridge
driver: bridge
# 前后端服务
services:
# 后端
backend:
image: eclipse-temurin:11-jre-alpine
container_name: test_backend
restart: always
ports:
- "8879:8879"
volumes:
- "/project/backend/:/data/"
networks:
- net
command: java -jar /data/app.jar --spring.config.location=file:/data/config/
# 前端
frontend:
image: nginx:latest
container_name: test_frontend
restart: always
ports:
- "8182:80"
volumes:
- "/project/frontend/:/data/"
networks:
- net
command: nginx -c /data/nginx.conf -g 'daemon off;'
Nginx配置
worker_processes 1;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 120;
gzip_static on;
# 配置后台服务
upstream wxjk {
# 这里可以用test_backend,也可以用backend,其中backend是别名
server backend:8879;
}
server {
listen 80;
location / {
root /data/dist;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
location /recordAPI/ {
proxy_pass http://wxjk/;
}
# 代理ws连接
location /wsUrl/ {
proxy_pass http://wxjk/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
Docker Compose命令
# 进入docker-compose.yml所在目录
cd /project/
# 启动
docker-compose up -d
# 关闭
docker-compose down
更多推荐
所有评论(0)