Deploy Docker App To Digitalocean

Deploy Docker App To Digitalocean

Reading time1 min
#Cloud#DevOps#Containers#Docker#DigitalOcean#Nodejs

Absolutely! Since the title, rationale, and hook are currently empty, I’ll create a practical, hands-on blog post on deploying a Docker app to DigitalOcean, focusing strictly on the deployment process with clear examples. If you provide specific title or rationale later, I can customize it further.


How to Deploy a Docker App to DigitalOcean: A Practical Step-by-Step Guide

Docker has revolutionized the way developers package and deploy applications by creating lightweight, portable containers. When combined with cloud providers like DigitalOcean, deploying your containerized app becomes both affordable and straightforward.

In this guide, I’ll walk you through how to deploy a simple Dockerized application to a DigitalOcean Droplet. We’ll cover everything from setting up the server to running your container in production – no fluff, just practical steps.


Why Deploy Docker Apps on DigitalOcean?

DigitalOcean offers powerful VMs (called Droplets) that are easy to spin up and manage. Pairing this infrastructure with Docker containers means your app is isolated, consistent across environments, and easy to update or scale. Plus, DigitalOcean's pricing is developer-friendly, making it ideal for startups, side projects, or learning.


Prerequisites

Before we dive in, make sure you have:

  • A DigitalOcean account (sign up here)
  • Basic knowledge of Docker
  • Docker installed locally on your machine
  • A simple Dockerized app ready (or use the example below)
  • An SSH client (like Terminal on Mac/Linux or PuTTY on Windows)

Step 1: Create Your Dockerized App

For the sake of demonstration, let's create a simple Node.js app with Docker.

1.1 Create project structure:

my-docker-app/
  ├── app.js
  ├── package.json
  └── Dockerfile

app.js

const http = require('http');

const server = http.createServer((req,res) => {
  res.writeHead(200, {'Content-Type':'text/plain'});
  res.end('Hello from Docker on DigitalOcean!');
});

server.listen(3000);
console.log('Server listening on port 3000');

package.json

{
  "name": "digitalocean-docker-app",
  "version": "1.0.0",
  "main": "app.js",
  "scripts": {
    "start": "node app.js"
  },
  "dependencies": {}
}

Dockerfile

FROM node:14-alpine

WORKDIR /app

COPY package.json ./
RUN npm install

COPY . .

EXPOSE 3000

CMD ["npm", "start"]

Step 2: Build and Test Your Docker Image Locally

Build your image:

docker build -t my-digitalocean-app .

Run it locally:

docker run -p 3000:3000 my-digitalocean-app

Visit http://localhost:3000 – you should see “Hello from Docker on DigitalOcean!”


Step 3: Create a Droplet on DigitalOcean

  1. Log in to your DigitalOcean dashboard.
  2. Click Create > Droplets
  3. Choose an OS image – I recommend Ubuntu 22.04 LTS
  4. Select Droplet plan – the basic $5/mo plan is fine for testing.
  5. Choose a data center region close to you.
  6. Add your SSH key (much safer than passwords).
  7. Finalize and create your Droplet.

Once created, note its public IP address – e.g., 123.45.67.89.


Step 4: Connect via SSH and Install Docker

Open your terminal:

ssh root@123.45.67.89

Once logged in, update apt and install some prerequisites:

apt update && apt upgrade -y
apt install -y ca-certificates curl gnupg lsb-release

Add Docker’s official GPG key and repository:

mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Install Docker Engine:

apt update
apt install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin

Check Docker status:

docker --version
systemctl status docker --no-pager

Make sure your user is added to the docker group (optional but recommended):

usermod -aG docker $USER
exit   # disconnect SSH and reconnect to apply group changes.

Reconnect via SSH.


Step 5: Transfer Your App’s Files or Use Git

The easiest way is using scp or rsync from your local machine.

Example using scp:

scp -r ./my-docker-app root@123.45.67.89:/root/

Alternatively, push your code to GitHub/GitLab and clone inside the droplet:

git clone https://github.com/yourusername/my-docker-app.git ~/my-docker-app
cd ~/my-docker-app/

Step 6: Build and Run Your Container on the Droplet

Navigate inside the project folder:

cd ~/my-docker-app/
docker build -t my-digitalocean-app .
docker run -d -p 80:3000 --name myapp my-digitalocean-app  

Explanation:

  • -d runs detached (in background)
  • -p 80:3000 maps droplet port 80 (HTTP) to container port 3000 (Node.js app)
  • --name myapp names your container for easy management

Step 7: Test Your Deployment!

Visit your Droplet IP in a browser:

http://123.45.67.89/

You should see “Hello from Docker on DigitalOcean!” live!


Optional: Set Up Restart Policy for Production Stability

Ensure your container restarts automatically if something goes wrong or if droplet reboots:

docker update --restart unless-stopped myapp 

Wrapping Up & Next Steps

Congrats! You’ve just deployed a real-world Docker container onto a remote cloud server.

From here you can explore more advanced topics like:

  • Using DigitalOcean Managed Kubernetes for scaling containers
  • Setting up Nginx as reverse proxy with SSL support
  • Automating deployment with CI/CD pipelines (GitHub Actions / GitLab CI)
  • Monitoring/logging tools like Prometheus + Grafana

But this foundation will serve you well in many projects requiring fast container deployment with affordable infrastructure.

Feel free to ask questions or share how you improved this workflow in the comments below!


Happy Dockering! 🚢


If you'd like me to tailor this post around a specific title or hook next time, just let me know!