简体   繁体   English

在 docker 容器中运行 angular 通用应用程序

[英]Run angular universal application in docker container

# common base image for development and 
FROM node:10.15.3 AS 
WORKDIR /app

ARG SC_NPM_TOKEN
ENV SC_NPM_TOKEN="${SC_NPM_TOKEN}"

# dev image contains everything needed for testing, development and building
FROM base AS development
COPY . /app

# install all dependencies and add source code
RUN npm install
RUN npm install -g @angular/cli@7.3.9

# builder runs unit tests and linter, then builds production code 
FROM development as builder
RUN npm run build:ssr --prod --output-path=dist
# RUN ls -ls ../
# RUN ls -ls .
# RUN pwd

# release includes bare minimum required to run the app, copied from builder
FROM base AS release
COPY --from=builder /app/dist /app/dist
COPY --from=builder /app/package.json /app/

ENV NODE_ENV "production"
ENV PORT 3000

EXPOSE 3000
CMD ["npm", "run ", "serve:ssr"]

When I use this Dockerfile, the container can be build and the nodejs application is started as well.当我使用这个 Dockerfile 时,可以构建容器并启动 nodejs 应用程序。 If I try to access the / route, the following error is thrown: Failed to lookup view "index" in views directory "/app/dist/browser" .如果我尝试访问 / 路由,则会引发以下错误: Failed to lookup view "index" in views directory "/app/dist/browser"

I took a look inside of the container and saw that the files are stored in /app/app/.我查看了容器内部,发现文件存储在 /app/app/ 中。 How can there be a second app directory?怎么会有第二个应用目录? If I move the files into the /app directory, everything works fine.如果我将文件移动到 /app 目录,一切正常。 As I don't understand how the second app directory is created, I can't seem to fix the Dockerfile.由于我不明白第二个应用程序目录是如何创建的,我似乎无法修复 Dockerfile。 I added a couple of debug commands, but I can't see the second app directory when the container is build.我添加了几个调试命令,但是在构建容器时我看不到第二个应用程序目录。

We don't know what the issue is, but we found a workaround.我们不知道问题是什么,但我们找到了解决方法。 The problem only occurs, when the container is build via the action defined in the github repo.仅当通过 github 存储库中定义的操作构建容器时,才会出现此问题。 As soon as we duplicated the repository (Create new Repo on github, Delete.git from project, Push to new repo), the new automatically build container just worked.一旦我们复制了存储库(在 github 上创建新的存储库,从项目中删除.git,推送到新的存储库),新的自动构建容器就可以工作了。 Might be a caching issue, but because of limited time we are just happy that it works for now.可能是一个缓存问题,但由于时间有限,我们很高兴它现在可以工作。

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

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