Angular 使用nginx“集装箱化角度应用程序;没有这样的文件或目录;

Angular 使用nginx“集装箱化角度应用程序;没有这样的文件或目录;,angular,docker,nginx,Angular,Docker,Nginx,我试图在docker容器中使用google cloud run部署我的angular应用程序 我的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/h

我试图在docker容器中使用google cloud run部署我的angular应用程序

我的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
似乎我已经尝试了一百万种不同的方法来处理dockerfile,但我认为这是让我走得最远的方法。 以下是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" "-"
以下是我的文件结构:

请帮帮忙!我快被这个容器弄得秃顶了

当我打开浏览器时,我得到以下信息:


您需要将dist文件夹(其中包含
index.html
)复制到nginx中的特定文件夹中,以便正确地提供服务。通过查看项目结构,我假设索引html位于
lumchtime
目录中。所以你要么改变你复制的东西

...
COPY dist/lumchtime /usr/share/nginx/html/
...
或访问以下网址的浏览器:
http://localhost:8080/lumchtime


另外,您在
lumchtime
中有一个输入错误,我想应该是
午餐时间。

我使用此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

并将google run container port设置为80

请使用您的NGINX配置更新问题。如何运行docker映像?我假设是docker run-p9000:80,因为您似乎在使用默认的ngnix配置,而默认的是监听80。您是否调用localhost:9000/usr/share/nginx/html和localhost:9000/html以在docker日志中获取该错误?你能给我们看看你的路由模块吗?