Skip to content

Instantly share code, notes, and snippets.

@resultakak
Created April 7, 2021 12:05
Show Gist options
  • Save resultakak/68973ab2bcb5e1148d9c5e7f3bf6a977 to your computer and use it in GitHub Desktop.
Save resultakak/68973ab2bcb5e1148d9c5e7f3bf6a977 to your computer and use it in GitHub Desktop.
Deploy a Node Js App to DigitalOcean Droplet with Docker

Deploy a Node Js App to DigitalOcean Droplet with Docker

mkdir digital-ocean
cd digital-ocean
npm init
npm install express
npm start
docker build . -t digital-ocean-app
docker run -p 3000:3000 digital-ocean-app
# Publish
docker tag digital-ocean-app <USER_NAME>/digital-ocean-app
docker tag digital-ocean-app <USER_NAME>/digital-ocean-app:<VERSION> # dev, staging, prod
docker login
docker push <USER_NAME>/digital-ocean-app:<OPTIONAL_VERSION>
FROM node:13-alpine
WORKDIR /user/src/app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD [ "npm", "start" ]
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}!`))
{
"name": "digital-ocean",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
ssh -i ~/.ssh/digital-ocean-key root@<IP_ADDRESS>
# docker login
docker run -p 3000:3000 <DOCKER_USER_NAME>/digital-ocean-app:<OPTIONAL_TAG>
ssh-keygen -t rsa -b 4096
# digital-ocean-key
cat digital-ocean-key.pub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment