Created
April 7, 2021 12:05
-
-
Save resultakak/68973ab2bcb5e1148d9c5e7f3bf6a977 to your computer and use it in GitHub Desktop.
Deploy a Node Js App to DigitalOcean Droplet with Docker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mkdir digital-ocean | |
cd digital-ocean | |
npm init | |
npm install express | |
npm start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM node:13-alpine | |
WORKDIR /user/src/app | |
COPY package*.json ./ | |
RUN npm install | |
COPY . . | |
EXPOSE 3000 | |
CMD [ "npm", "start" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}!`)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ssh -i ~/.ssh/digital-ocean-key root@<IP_ADDRESS> | |
# docker login | |
docker run -p 3000:3000 <DOCKER_USER_NAME>/digital-ocean-app:<OPTIONAL_TAG> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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