skip to Main Content

So i am new to Docker and i am following this tutorial to a point .
https://owen31302.gitbook.io/github-education/digital-ocean/deploy-node-js-on-digitalocean-droplet-using-docker

to set up docker on digital ocean, i followed this
https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-20-04

and it worked without trouble

Now here is what, i installed git on the server because i wanted to use git to Clone the web app, then I did

git clone https://github.com/EmekaIwuagwu/docker_test1.git

and pulled the app into the server with git, then i cd into the folder

cd docker_test1

then ran docker build command like this

docker build . -t digital-ocean-app

Now the app built successfully inside the Digitalocean VPS Linux box

running docker images i have this

REPOSITORY          TAG       IMAGE ID       CREATED         SIZE
digital-ocean-app   latest    d375b6e4c37f   3 minutes ago   122MB
hello-world         latest    9c7a54a9a43c   3 months ago    13.3kB

As you can see , there is digital ocean app there

Now i run it like this

docker run digital-ocean-app:latest

it starts the Node app as seen here

root@testdocker:~/docker_test1# docker run digital^Ccean-app:latest
root@testdocker:~/docker_test1# docker run digital-ocean-app:latest

> [email protected] start /usr/src/app
> node index.js

Example app listening on port 3000!

But rather than show in the browser , i am getting Connection refused.

http://167.71.30.198:3000/status

What am i getting wrong?

2

Answers


  1. Chosen as BEST ANSWER

    So i fixed it.

    Here is a step by step method on how I achieved it.

    1.) Create and push the code (Together with the Docker file.) as shown in the Github For the sake of Clarity i will be sharing here

    Node.js app

    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}!`));
    

    Dockerfile

    FROM node:13-alpine
    
    WORKDIR /usr/src/app
    
    COPY package*.json ./
    
    RUN npm install
    
    COPY . .
    
    EXPOSE 3000
    CMD [ "npm", "start" ]
    

    And push code to Git repo

    2.) Login to Digital ocean Linux vps (i used Ubuntu) in my case. And followed setup here to setup everything https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-20-04

    3.) Do a Git clone my case , i installed git inside the server then did a Git Clone like this git clone https://github.com/EmekaIwuagwu/docker_test1.git

    4.) then I do a Docker Build like this docker build . -t digital-ocean-app

    5.) After which i followed suit by running the final command to run the app inside my server. This is how i ran the server

    docker run -d -p 3000:3000 digital-ocean-app
    

    6.) Running docker ps everything is up and fine

    Now checking from the browser

    james.png


  2. Docker may not be the top choice for Node.js deployment due to its complexity, performance overhead, and resource usage. This can result in memory leaks and recurrent container downtimes as server load increases. Additionally, it might necessitate a powerful server for scalability.

    Alternatively, you could opt for PM2, a simpler solution for deploying Node.js projects efficiently.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search