首页 > 解决方案 > 使用 docker 容器中的 startup.sh 文件构建具有动态环境的 Angular 应用程序

问题描述

所以我使用 gcloud run 来部署我的 docker 容器和我的 Angular 应用程序。这是我的文件结构:

在此处输入图像描述

在我的 docker 文件夹中有一个我想运行的 startup.sh 文件。

我的 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/

RUN npm run build -- --output-path=./dist/out
# 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

COPY ../docker /app/
WORKDIR /app/docker
RUN /startup.sh 

当 gcloud 运行我的 dockerfile 时,我总是收到此错误:

/bin/sh: 1: /startup.sh: not found

所以我想我的 docker 文件夹副本没有像我认为的那样正常工作,或者我可能不在正确的文件夹中。我对 docker 很陌生,所以我可能在这里错过了一些非常基本的东西。

标签: angulardockernginxgcloud

解决方案


尝试添加绝对路径。

确保在容器中安装了 bash。

添加执行文件的权限。

尝试使用CMD.

COPY /docker /app/
RUN apk add --no-cache bash
RUN chmod +x /app/docker/startup.sh
# RUN /app/docker/startup.sh
CMD ["/bin/bash", "-c", "/app/docker/startup.sh"]

推荐阅读