我有一个VueJS应用,该应用带有dockerized的NestJS后端。我有一个运行nginx的容器,VueJS应用存储在/usr/share/nginx/html
文件夹中。另一个容器正在运行我的NestJS支持。在Mac上构建并部署容器后,一切工作均正常。
我从图像创建了tar文件,将它们传输到远程服务器,然后为每个文件运行docker load -i
。
我还复制了用于在Mac上构建的同一docker-compose文件。
我在远程服务器上执行了docker-compose up
。容器成功启动,但是当我访问http://remote-host
时,看到的是nginx默认页面。
有人知道为什么会这样吗?我花了几天时间试图找到解决方案。
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;
}
}
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;"]
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"]
看来整个过程只需要一些时间。刷新后,将忠实地显示我的应用程序的主页!