用吞噬任务暴露heroku $ PORT
我正在用下面的Dockerfile
构build一个Docker镜像
FROM node:latest RUN npm install -g gulp # Create app directory RUN mkdir -p /usr/src/app WORKDIR /usr/src/app # Install app dependencies COPY package.json /usr/src/app/ RUN npm install # Bundle app source COPY . /usr/src/app EXPOSE 5000 CMD ["gulp", "serveprod"]
我知道我需要从heroku文档公开$PORT
variables。
但是,我不知道这是如何与吞咽工作。
这是我的gulpfile.js
和serveprod
任务。
gulp.task('serveprod', function() { connect.server({ root: './', port: $PORT || process.env.PORT || 5000, // localhost:5000 livereload: false }); });
以前,我使用节点buildpack和所有我需要的port:
process.env.PORT
,它会工作得很好。 我已经尝试添加$PORT
但这仍然无法正常工作。
更新:
我只是试图把它放在我的Dockerfile中
ENV 5000 $PORT
这里是Heroku日志:
2017-07-07T15:01:27.127275+00:00 heroku[web.1]: Starting process with command `gulp serveprod` 2017-07-07T15:01:29.985824+00:00 heroku[web.1]: State changed from starting to crashed 2017-07-07T15:01:29.875500+00:00 app[web.1]: module.js:487 2017-07-07T15:01:29.875515+00:00 app[web.1]: throw err; 2017-07-07T15:01:29.875517+00:00 app[web.1]: ^ 2017-07-07T15:01:29.875517+00:00 app[web.1]: 2017-07-07T15:01:29.875518+00:00 app[web.1]: Error: Cannot find module './lib/_stream_readable.js' 2017-07-07T15:01:29.875519+00:00 app[web.1]: at Function.Module._resolveFilename (module.js:485:15) 2017-07-07T15:01:29.875519+00:00 app[web.1]: at Function.Module._load (module.js:437:25) 2017-07-07T15:01:29.875520+00:00 app[web.1]: at Module.require (module.js:513:17) 2017-07-07T15:01:29.875521+00:00 app[web.1]: at require (internal/module.js:11:18) 2017-07-07T15:01:29.875539+00:00 app[web.1]: at Object.<anonymous> (/usr/local/lib/node_modules/gulp/node_modules/through2/node_modules/readable-stream/readable.js:12:30) 2017-07-07T15:01:29.875540+00:00 app[web.1]: at Module._compile (module.js:569:30) 2017-07-07T15:01:29.875541+00:00 app[web.1]: at Object.Module._extensions..js (module.js:580:10) 2017-07-07T15:01:29.875541+00:00 app[web.1]: at Module.load (module.js:503:32) 2017-07-07T15:01:29.875542+00:00 app[web.1]: at tryModuleLoad (module.js:466:12) 2017-07-07T15:01:29.875543+00:00 app[web.1]: at Function.Module._load (module.js:458:3) 2017-07-07T15:01:29.971237+00:00 heroku[web.1]: Process exited with status 1 2017-07-07T15:01:32.103467+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=www.christopherdbolton.com request_id=469ad736-103a-461f-af20-91454a8a83f1 fwd="139.72.158.28" dyno= connect= service= status=503 bytes= protocol=http 2017-07-07T15:01:32.923798+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=www.christopherdbolton.com request_id=a5c0b8c4-69c7-4bd7-ab00-372fe625b2f8 fwd="139.72.158.28" dyno= connect= service= status=503 bytes= protocol=http Disconnected from log stream. There may be events happening that you do not see here! Attempting to reconnect... 2017-07-07T15:01:29.875520+00:00 app[web.1]: at Module.require (module.js:513:17) 2017-07-07T15:01:29.875521+00:00 app[web.1]: at require (internal/module.js:11:18) 2017-07-07T15:01:29.875539+00:00 app[web.1]: at Object.<anonymous> (/usr/local/lib/node_modules/gulp/node_modules/through2/node_modules/readable-stream/readable.js:12:30) 2017-07-07T15:01:29.875541+00:00 app[web.1]: at Object.Module._extensions..js (module.js:580:10) 2017-07-07T15:01:29.875540+00:00 app[web.1]: at Module._compile (module.js:569:30) 2017-07-07T15:01:29.875541+00:00 app[web.1]: at Module.load (module.js:503:32) 2017-07-07T15:01:29.875542+00:00 app[web.1]: at tryModuleLoad (module.js:466:12) 2017-07-07T15:01:29.875543+00:00 app[web.1]: at Function.Module._load (module.js:458:3)
从npm start
,而不是从gulp serveprod
npm start
。
这是得到的Dockerfile:
FROM node:latest RUN npm install -g gulp # Create app directory RUN mkdir -p /usr/src/app WORKDIR /usr/src/app # Install app dependencies COPY package.json /usr/src/app/ RUN npm install # Bundle app source COPY . /usr/src/app CMD ["npm", "start"]
这里是package.json
:
"scripts": { "build": "gulp", "start": "gulp serveprod" }