首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Docker Container在本地工作,但在服务器上失败

Docker Container在本地工作,但在服务器上失败
EN

Stack Overflow用户
提问于 2017-06-06 20:42:49
回答 1查看 1.1K关注 0票数 0

我是docker的新手,我正在尝试使用Angular CLI应用程序。我设法通过我的docker容器在本地运行它。它工作得很好,但是当我尝试从我的服务器上运行它时,它失败了。

服务器托管在DigitalOcean上:

代码语言:javascript
复制
512 MB Memory / 20 GB Disk / FRA1 - Ubuntu Docker 17.03.0-ce on 14.04    

我使用dockerhub将我的容器传输到服务器。

在记录容器日志时,它给我提供了以下内容:

代码语言:javascript
复制
** NG Live Development Server is running on http://0.0.0.0:4200. **
 63% building modules 469/527 modules 58 active ...s/@angular/compiler/src/assertions.jsKilled

npm info lifecycle angular-test@0.0.0~start: Failed to exec start script
npm ERR! Linux 4.4.0-64-generic
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
npm ERR! node v6.10.3
npm ERR! npm  v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! angular-test@0.0.0 start: `ng serve --host 0.0.0.0`
npm ERR! Exit status 137
npm ERR! 
npm ERR! Failed at the angular-test@0.0.0 start script 'ng serve --host 0.0.0.0'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the angular-test package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     ng serve --host 0.0.0.0
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs angular-test
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls angular-test
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /usr/src/app/npm-debug.log

这是我的Dockerfile:

代码语言:javascript
复制
# Create image based on the official Node 6 image from dockerhub
FROM node:6

# Create a directory where our app will be placed
RUN mkdir -p /usr/src/app

# Change directory so that our commands run inside this new directory
WORKDIR /usr/src/app

# Copy dependency definitions
COPY package.json /usr/src/app

# Install dependecies
RUN npm install

# Get all the code needed to run the app
COPY . /usr/src/app

# Expose the port the app runs in
EXPOSE 4200

# Serve the app
CMD ["npm", "start"]

为什么它在本地运行,在服务器上失败?我是否遗漏了一些依赖项?

EN

回答 1

Stack Overflow用户

发布于 2017-06-06 20:48:56

ng serve是一个angular-cli命令。我猜如果你想在数字海洋上像这样启动你的服务器,你需要在你的docker文件中全局安装它:

代码语言:javascript
复制
RUN npm i -g angular-cli

我认为更典型的做法是在生产环境中使用裸节点服务器来运行应用程序。所以你的CMD看起来更像这样:

代码语言:javascript
复制
CMD ["node", "app.js"]
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44390338

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档