How to deploy NodeJS application to Heroku using docker
Create a project in your local
>> npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.
See `npm help json` for definitive documentation on these fields
and exactly what they do.
Use `npm install <pkg>` afterwards to install a package and
save it as a dependency in the package.json file.
Press ^C at any time to quit.
package name: (heroku-nodejs-docker)
version: (1.0.0)
description:
entry point: (server.js)
test command:
git repository: (https://github.com/xx/Heroku-NodeJs-docker.git)
keywords:
author:
license: (ISC)
About to write to /Users/xx/Documents/GitHub/Heroku-NodeJs-docker/package.json:
{
"name": "heroku-nodejs-docker",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/xx/Heroku-NodeJs-docker.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/xx/Heroku-NodeJs-docker/issues"
},
"homepage": "https://github.com/xx/Heroku-NodeJs-docker#readme"
}
Is this OK? (yes)
Create simple NodeJS application
server.js
Write your docker file
Build the image on top of light weight linux (alpine) and install express.
Dockerfile
Login to heroku cli
Login to heroku container
Create target application
Connect you local git to remote heroku git
Build the image and push to Container Registry
Then release the image to your app
Verify the nodeJS application in your browser
Logout the container when you're done
Last updated
Was this helpful?