Deploy nodeJs on DigitalOcean droplet using docker

Good reference

https://stackabuse.com/deploying-a-node-js-app-to-a-digitalocean-droplet-with-docker/

The following steps are my walk through of the above steps.

Test Nodejs server

Create sample node js app

>> npm init

Install express

>> npm install express --save

Add index.js

const express = require('express');
const app = express();
const port = 3000;

app.get('/status', (req, res) => res.send({status: "I'm alive!"}));

app.listen(port, () => console.log(`Example app listening on port ${port}!`));

Add start command in package.json

Test locally

Check browser

You can check the page by access url http://localhost:3000/status

Create my own docker image on docker hub

Create docker file

Create a docker file with name Dockerfile

Build docker image using docker file

Check your image locally

Test your image locally

Check browser

You can check the page by access url http://localhost:3000/status

Publishing the Image to Docker Hub

In this way, you can pull/run your docker anywhere.

Before you push your images to docker hub, you need to specify your user name as tag

Check your docker images again

Login to docker hub

Push your image to docker hub

Deploy your docker image on DigitalOcean droplet

Access your droplet via ssh

Check docker version on your droplet

Run your docker image on droplet

Check browser

You can check the page by access url

Last updated

Was this helpful?