我有一个云服务器ubuntu 18.04,我有一个后端API( .NET Core )和一个前端 Angular 应用程序(两个应用程序均已部署)在docker容器中)。后端API首先上传,因此我在云服务器上配置了Nginx代理。然后当我对Angular应用程序进行dockerize时,但所有示例都通过nginx进行了dockerized。是否可以在没有nginx的情况下独立实现Angular应用的docker化?
因此,现在,云服务器具有两个Nginx反向代理。一台在服务器上,一台在Angular容器@@
我的想法
答案 0 :(得分:1)
在评论部分进行讨论之后,我想我将分享我的angular-app Dockerfile和Docker组成配置文件以供参考:
FROM node:12-alpine
ARG mode=prod
ENV mode=$mode
RUN apk --no-cache add \
tzdata \
git \
python \
g++ \
make
ENV TZ=${TZ:-America/Chicago}
RUN echo "$TZ" > /etc/timezone && date
EXPOSE 4200
USER node
WORKDIR /home/node
#To take advantage of docker's caching, first only copy the package.json and
# package-lock.json, then run npm install
COPY package*.json ./
RUN npm install
#This way the node_modules will be stored in an image build stage cache,
# which means it won't need to reinstall node_modules every build, but will
# reinstall them if either the package.json or package-lock.json file changes.
COPY *.js* ./
COPY src ./src
RUN [[ -z $mode ]] && npm run build || npm run build:$mode
泊坞窗撰写:
version: '3.4'
services:
express-api:
container_name: express-api
build: ./express-api
user: ${DOCKER_USER:-0:0}
expose:
- "3000"
restart: "unless-stopped"
environment:
- TZ=America/Chicago
volumes:
- ./express-api/ssl-certs/:/home/node/ssl-certs:ro
angular-app:
container_name: angular-app
build: ./angular-app
user: ${DOCKER_USER:-0:0}
expose:
- "4200"
restart: "on-failure"
environment:
- TZ=America/Chicago
volumes:
- app_dist:/home/node/dist
- ./angular-app/ssl-certs/:/home/node/ssl-certs:ro
angular-docs:
container_name: angular-docs
build:
context: ./angular-app
dockerfile: Dockerfile-docs
user: ${DOCKER_USER:-0:0}
expose:
- "8080"
restart: "on-failure"
environment:
- TZ=America/Chicago
nginx-server:
container_name: nginx-server
build: ./nginx-server
expose:
- "80"
- "443"
restart: "unless-stopped"
environment:
- TZ=America/Chicago
volumes:
- ./nginx-server/nginx.conf:/etc/nginx/nginx.conf:ro
- ./nginx-server/ssl-certs/:/etc/nginx/ssl-certs:ro
- app_dist:/var/www:ro
volumes:
app_dist:
然后我将组成文件与此文件合并以进行生产:
version: '3.4'
services:
express-api:
env_file: prod.env
angular-app:
build:
args:
mode: "prod"
env_file: prod.env
nginx-server:
ports:
- "80:80"
- "443:443"
env_file: prod.env
在我的角度包json中,我有以下脚本:
"build": "node --max_old_space_size=4096 node_modules/@angular/cli/bin/ng build",
"build:prod": "node --max_old_space_size=4096 node_modules/@angular/cli/bin/ng build --prod",
我在发布之前从其中删除了一些行,但是它们应该可以帮助您入门。此设置使用一个容器来构建angular-app分发文件,并将其存储在与nginx容器共享的卷中,该容器为文件提供服务并具有express-api后端的反向代理。
bash脚本预先使用以下命令设置了DOCKER_USER env变量:
export DOCKER_USER="${USERID:-1000}:${USERGID:-1000}"