diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2478599 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +# 使用 node 构建阶段 +FROM node:18 AS builder +WORKDIR /app +COPY . . +RUN npm install && npm run build + +# 使用 nginx 作为生产环境 +FROM nginx:stable-alpine +COPY --from=builder /app/dist /usr/share/nginx/html +COPY nginx.conf /etc/nginx/conf.d/default.conf diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..934945f --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,11 @@ +version: '3.8' + +services: + vue-app: + build: + context: . + dockerfile: Dockerfile + ports: + - "55511:80" + container_name: vue3-nginx + restart: unless-stopped diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..cbb6356 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,11 @@ +server { + listen 80; + server_name localhost; + + root /usr/share/nginx/html; + index index.html; + + location / { + try_files $uri $uri/ /index.html; + } +}