【发布时间】:2018-10-23 15:41:01
【问题描述】:
我的目标是使用 nginx 在容器中运行 angular app。 我希望带有应用程序的容器位于我的主机网络中。
这是我的 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 不服务应用?
【问题讨论】:
-
你有没有在 docker-compose.yml 中映射 80 端口? “什么都没有”是什么意思?
-
如果使用“主机”模式作为网络模式,则不需要映射任何端口
标签: angular docker nginx docker-compose