expose heroku $PORT with gulp task

I am building a Docker image with the following 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

EXPOSE 5000

CMD ["gulp", "serveprod"]

I know I need to expose the $PORT variable from the heroku documents.

  • How to deal with files of web applications in docker?
  • Efficient Dockerfile for many apt-get packages
  • How to run sql script for postgres in docker
  • Docker tutum/wordpress container issues with apache2 and supervisor
  • Link & Expose Docker Container Simultaniously
  • Using Docker and Dependecy Injection Framewrok
  • However, I do not know how this works with gulp.

    Here is my gulpfile.js and the serveprod task.

    gulp.task('serveprod', function() {
        connect.server({
            root: './',
            port: $PORT || process.env.PORT || 5000, // localhost:5000
            livereload: false
        });
    });
    

    Previously, I was using the node buildpack and all I needed for the port: was process.env.PORT and it would work just fine. I have tried adding the $PORT but this still isn’t working.

    UPDATE:

    I just tried putting this in my Dockerfile

    ENV 5000 $PORT
    

    Here are the Heroku logs:

    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)
    

  • Docker External File Access Not in /Users/ on OSX
  • How to deal with state “Exit 0” in Docker
  • Docker Compose stuck downloading or pulling fs layer
  • Docker cannot run
  • Amazon ECS private DockerHub repo: Unable to decode provided docker credentials error
  • Docker: Couldn't connect to docker daemon at http+docker://localunixsocket -is it running?
  • One Solution collect form web for “expose heroku $PORT with gulp task”

    Instead of starting with gulp serveprod, start with npm start.

    Here is the resulting 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"]
    

    Here is the package.json:

      "scripts": {
        "build": "gulp",
        "start": "gulp serveprod"
      }
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.