首页 > 解决方案 > 主机网络上的 Nginx docker 容器不提供 Angular 应用程序

问题描述

我的目标是使用nginx在容器中运行Angular 应用程序。我希望带有应用程序的容器位于我的主机网络中。

这是我的 Dockerfile:

# Stage 1
FROM node:10.11.0-alpine as node

WORKDIR /usr/src/app

COPY package*.json ./

RUN npm ci

COPY . .

RUN npm run build

# Stage 2
FROM nginx:1.14-alpine

COPY --from=node /usr/src/app/dist/gui /usr/share/nginx/html

COPY ./nginx.conf /etc/nginx/conf.d/default.conf

nginx.conf:

server {
  listen 80;
  server_name 127.0.0.1;
  location / {
    root /usr/share/nginx/html;
    index index.html index.html;
    try_files $uri $uri/ /index.html =404;
  }

  location /api {
    proxy_pass http://localhost:8080/api;
  }
}

还有我的 docker-compose.yml 文件:

version: "3.5"

services:
  gui:
    container_name: gui
    network_mode: "host"
    build:
        context: gui

$ docker-compose up启动容器。但是localhost:80上没有任何内容。

问题出在哪里?Nginx 不服务应用程序?

标签: angulardockernginxdocker-compose

解决方案



推荐阅读