简体   繁体   English

使用 nginx 容器化 Angular 应用程序“没有这样的文件或目录”

[英]containerizing angular app with nginx "no such file or directory"

Im trying to deploy my angular app using google cloud run in an docker container.我正在尝试使用在 docker 容器中运行的谷歌云部署我的 angular 应用程序。

My dockerfile looks like this:我的 dockerfile 看起来像这样:

# stage 1

FROM node:alpine AS my-app-build
WORKDIR /app
COPY . .
RUN npm ci && npm run build

# stage 2

FROM nginx:alpine
COPY --from=my-app-build /app/dist /usr/share/nginx/html
EXPOSE 8080

And it seems that i have tried one milion different approaches to the dockerfile but i think this one is the one that have gotten me furthest.似乎我已经尝试了 100 万种不同的 dockerfile 方法,但我认为这是让我走得最远的一种。 Here is the docker logs:这是docker日志:

/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration

/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/

/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh

10-listen-on-ipv6-by-default.sh: Getting the checksum of /etc/nginx/conf.d/default.conf

10-listen-on-ipv6-by-default.sh: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf

/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh

/docker-entrypoint.sh: Configuration complete; ready for start up

2020/11/20 20:23:49 [error] 29#29: *3 open() "/usr/share/nginx/html/usr/share/nginx/html" failed (2: No such file or directory), client: 172.17.0.1, server: localhost, request: "GET /usr/share/nginx/html HTTP/1.1", host: "localhost:9000"

172.17.0.1 - - [20/Nov/2020:20:23:49 +0000] "GET /usr/share/nginx/html HTTP/1.1" 404 555 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36" "-"

2020/11/20 20:23:54 [error] 29#29: *5 open() "/usr/share/nginx/html/html" failed (2: No such file or directory), client: 172.17.0.1, server: localhost, request: "GET /html HTTP/1.1", host: "localhost:9000"

172.17.0.1 - - [20/Nov/2020:20:23:54 +0000] "GET /html HTTP/1.1" 404 555 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36" "-"

Here is my file-structure:这是我的文件结构:

在此处输入图片说明

Please help with this!请帮忙解决这个问题! I'm about to run bald with this container thing....我快要被这个容器的东西秃顶了....

When I open the browser I get this:当我打开浏览器时,我得到了这个:

在此处输入图片说明

I managed to do what i wanted using this dockerfile:我设法使用这个 dockerfile 做我想做的事:

# Stage 0, "build-stage", based on Node.js, to build and compile the frontend
FROM tiangolo/node-frontend:10 as build-stage
WORKDIR /app
COPY package*.json /app/
RUN npm install
COPY ./ /app/
ARG configuration=production
RUN npm run build -- --output-path=./dist/out --configuration $configuration
# Stage 1, based on Nginx, to have only the compiled app, ready for production with Nginx
FROM nginx:1.15
COPY --from=build-stage /app/dist/out/ /usr/share/nginx/html
# Copy the default nginx.conf provided by tiangolo/node-frontend
COPY --from=build-stage /nginx.conf /etc/nginx/conf.d/default.conf

and set google run container port to 80并将谷歌运行容器端口设置为 80

You need to copy your dist folder (the one with index.html inside) to a specific folder in nginx, so it's served properly.您需要将您的 dist 文件夹(里面有index.html文件夹)复制到 nginx 中的一个特定文件夹,这样它才能正常运行。 By looking at your project structure, I assume, that your index html is inside lumchtime directory.通过查看您的项目结构,我假设您的索引 html 位于lumchtime目录中。 So you either change what you copy所以你要么改变你复制的东西

...
COPY dist/lumchtime /usr/share/nginx/html/
...

or access browser at: http://localhost:8080/lumchtime或访问浏览器: http://localhost:8080/lumchtime

PS you have a typo in lumchtime , I guess it should be lunchtime instead. PS 你在lumchtime有一个错字,我想应该是lunchtime

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM