【发布时间】:2020-06-06 03:34:08
【问题描述】:
我有一个 VueJS 应用程序,它的 NestJS 后端是 dockerized。我有一个运行 nginx 的容器,VueJS 应用程序存储在 /usr/share/nginx/html 文件夹中。另一个容器正在运行我的 NestJS 支持。在我的 Mac 上构建和部署容器后,一切正常。
我从图像创建了 tar 文件,将它们传输到远程服务器,然后为每个图像运行 docker load -i。
我还复制了我在 Mac 上构建时使用的同一个 docker-compose 文件。
我在远程服务器上执行了docker-compose up。容器成功启动,但是当我访问http://remote-host 时,我看到的是 nginx 默认页面。
有人知道为什么会这样吗?我花了几天的时间试图找到解决方案。
nginx.conf
upstream api {
server api:3000;
}
server {
listen 80;
location / {
root /usr/share/nginx/html;
try_files $uri $uri/ /index.html;
}
location /essj-api {
proxy_pass http://api;
}
}
docker-compose.yml
version: "3.8"
services:
api:
build: ./api
container_name: 'api-v5'
ports:
- '3000:3000'
client:
build: ./client
container_name: 'client-v5'
ports:
- '80:80'
depends_on:
- api
客户端泊坞窗文件
# build stage
FROM node:lts-alpine as build-stage
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
# production stage
FROM nginx:alpine as production-stage
COPY --from=build-stage /app/dist /usr/share/nginx/html
RUN rm /etc/nginx/conf.d/default.conf
COPY nginx/nginx.conf /etc/nginx/conf.d
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
api docker 文件
FROM node:12.9 AS builder
WORKDIR /app
COPY ./package.json ./
RUN npm install
COPY . .
RUN npm run build
# Second Stage : Setup command to run your app using lightweight node image
FROM node:12.9-alpine
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
WORKDIR /app
COPY --from=builder /app ./
EXPOSE 3000
CMD ["npm", "run", "start:prod"]
【问题讨论】:
标签: vue.js docker-compose nginx-location nginx-config