【问题标题】:Can't dockerize angular application无法码头化角度应用程序
【发布时间】:2020-12-15 22:27:26
【问题描述】:

我一直在尝试将我的 Angular 应用程序的 docker 映像推送到 azure,但没有成功。

我按照此页面上视频中的步骤操作:https://docs.microsoft.com/en-us/azure/developer/javascript/tutorial-vscode-docker-node-01?tabs=bash,但是我得到了 :( 应用程序错误屏幕。然后我尝试在本地运行 docker 容器,这给了我以下错误:

$ docker run angdocker

> angdocker@0.0.0 start /usr/src/app
> ng serve

sh: ng: not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! angdocker@0.0.0 start: `ng serve`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the angdocker@0.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-08-27T04_17_03_098Z-debug.log

我会指出我在 Ubuntu 20.0.4 上,这是一个简单的 Angular 应用程序,我开始使用 ng new 命令并且没有编辑。我只是使用 VS 代码生成 dockerfile 图像来创建图像并从那里开始工作。任何帮助将不胜感激,谢谢!

【问题讨论】:

标签: angular azure docker npm


【解决方案1】:

看来您需要安装依赖项,在ng serve 之前使用npm install。或者你可以在你的 Dockerfile 中写这个,你还需要一个服务器来服务 HTTP 请求。像 nginx。

或者你可以关注这个 Dockerfile。创建 docker 镜像

# stage 1   
FROM node:latest as node
WORKDIR /app
COPY . .
RUN npm install
RUN npm run build --prod
    
# stage 2
FROM nginx:alpine
COPY --from=node /app/dist/angular-app /usr/share/nginx/html

【讨论】:

    猜你喜欢
    • 2020-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-13
    • 2023-03-16
    • 2021-08-17
    相关资源
    最近更新 更多