[英]How to deploy Angular app under container of nginx?
I'm trying to deploy Angular app under docker Nginx.我正在尝试在 docker Nginx 下部署 Angular 应用程序。 My config is next:
我的配置是下一个:
./Dockerfile ./Dockerfile
FROM node:12-alpine AS builder
ENV NODE_ENV production
WORKDIR /usr/src/app
COPY ["package.json", "yarn.lock", "./"]
RUN yarn install --production=false
COPY . .
RUN yarn build
FROM nginx:alpine
COPY --from=builder /usr/src/app/dist/angular-nginx/* /usr/share/nginx/html/
COPY ./nginx.conf /etc/nginx/conf.d/default.conf
./nginx.conf ./nginx.conf
server {
listen 80;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html =404;
}
}
The app works, but its assets like images doesn't load (On development assets works).该应用程序有效,但其图像等资产无法加载(在开发资产上有效)。
And if I try to access directly to http://localhost:4000/assets/img/logo.png always go to http://localhost:4000/如果我尝试直接访问http://localhost:4000/assets/img/logo.png总是去http://localhost:4000/
What is my mistake?, thank you very much for the help.我的错误是什么?,非常感谢您的帮助。
the problem is probabably in this command问题可能出在这个命令中
COPY --from=builder /usr/src/app/dist/angular-nginx/* /usr/share/nginx/html/
should be应该
COPY --from=builder /usr/src/app/dist/angular-nginx/ /usr/share/nginx/html/
with your variant you are copying just the first layer of the directory and just COPY dir/
should do the thing使用您的变体,您只复制目录的第一层,只需
COPY dir/
完成此操作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.