angular - 主机网络上的 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 不服务应用程序?
解决方案
- 你不启动 nginx,把这个
CMD ["nginx", "-g", "daemon off;"]
Dockerfile 的结尾。官方 Nginx Dockerfile
推荐阅读
- java - GenericContainer 不拾取文件进行处理
- vue.js - 选择选项始终被选中并隐藏
- python - Python 2.x 和 3.x 无源 .pyc 部署
- node.js - 数据:hapi.js preResponse 中的 null,如果抛出错误
- powershell - 将 ZIP 文件上传到 Jenkins 并在 Jenkins 中使用 Powershell 命令提取 ZIP 文件
- linux - 如何检查当前时间格式是否为 12 小时
- oracle - LDAP: Empty binddn"" 和身份验证类型从无变得简单
- linux - 在bash中匹配逗号分隔列表中的单词
- c# - 如何使用 rest api 在 DocuSign 中创建信封的副本?
- keras - 如何解释等级为 3 的 Keras Dense 层