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

我对docker相当陌生,而且我正在尝试Angular CLI应用。 我设法通过我的docker集装箱在本地运行它。 它工作的很好,但是当我尝试从我的服务器运行它失败。

服务器在DigitalOcean上托pipe:

512 MB Memory / 20 GB Disk / FRA1 - Ubuntu Docker 17.03.0-ce on 14.04 

我用dockerhub将我的容器转移到服务器。

当logging容器时,它给了我这个:

 ** 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:

 # 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"] 

它如何在本地运行,并在服务器上失败? 我错过了一些依赖?

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

 RUN npm i -g angular-cli 

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

 CMD ["node", "app.js"]