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

时间:2017-06-06 12:42:49

标签: docker docker-container

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

服务器托管在DigitalOcean上:

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

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

记录容器时,它给了我:

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

为什么它在本地运行并在服务器上失败?我错过了一些依赖项吗?

1 个答案:

答案 0 :(得分:0)

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

RUN npm i -g angular-cli

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

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