# 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"]
当我使用这个Dockerfile的时候,容器可以被构建,并且nodejs应用程序也启动了。如果我尝试访问 / 路径,会抛出以下错误:
Failed to lookup view "index" in views directory "/app/dist/browser"
。我查看了容器内部并发现文件存储在 /app/app/ 中。怎么可能有第二个 app 目录呢?如果我将文件移动到 /app 目录中,一切都能正常工作。由于我不明白第二个 app 目录是如何创建的,所以无法修复 Dockerfile。我添加了一些调试命令,但是在构建容器时看不到第二个 app 目录。
docker run -v
或 Docker Compose 的volumes:
选项来隐藏镜像中的/app
目录?) - David Maze