Deploying Your Web App to DigitalOcean with Docker Compose
If you’ve containerized your web application using Docker, the next logical step is deployment. Among the many hosting platforms available, DigitalOcean stands out for its developer-friendly infrastructure, predictable pricing, and ease of use. Paired with Docker Compose, it allows you to manage multi-service applications with just a few commands.
In this guide, you’ll learn how to deploy a full-stack web application to a DigitalOcean Droplet using Docker Compose. Whether you’re working with Node.js, Django, Laravel, or any other stack, the principles here apply to nearly any containerized setup.
Prerequisites
Before starting, make sure you have:
- A DigitalOcean account
- A Dockerized application with a
docker-compose.ymlfile - Basic familiarity with using the terminal
- SSH access set up for your Droplet
You’ll also need to install the following on your local machine:
- Docker
- Docker Compose
- An SSH client (built-in on Linux/macOS; use PuTTY or similar on Windows)
Step 1: Create a DigitalOcean Droplet
- Log in to the DigitalOcean dashboard.
- Click Create > Droplets.
- Choose an image (use Ubuntu 22.04 LTS).
- Select a plan (a Basic Shared CPU plan is fine for small projects).
- Add your SSH key or set a root password.
- Choose a data center region.
- Click Create Droplet.
Once the Droplet is ready, note its IP address , you’ll use it to connect and deploy your app.
Step 2: Connect to Your Droplet via SSH
ssh root@your_droplet_ip
If you added an SSH key during setup, the login should be seamless. If using a password, enter it when prompted.
Step 3: Install Docker and Docker Compose on the Server
Install Docker
apt update
apt install -y docker.io
systemctl enable docker
systemctl start docker
Install Docker Compose
curl -L "https://github.com/docker/compose/releases/download/v2.22.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
Verify the installation:
docker -v
docker-compose -v
Step 4: Upload Your Project Files
You can use scp to copy your project folder from your local machine to the server:
scp -r ./your-app-folder root@your_droplet_ip:/root/
Or, clone your repository directly on the server if it’s hosted on GitHub:
git clone https://github.com/yourusername/your-app.git
cd your-app
Make sure your docker-compose.yml is in the root of the project directory.
Step 5: Run Docker Compose
Inside your project folder on the server, start your application:
docker-compose up -d
The -d flag runs your containers in detached mode. You can now access your web app via the Droplet’s public IP (assuming your docker-compose.yml exposes port 80 or 443).
Step 6: Configure a Domain (Optional)
To point your custom domain to your app:
- Go to your domain registrar.
- Create an A record pointing to your Droplet’s IP address.
- On the server, set up Nginx and Certbot if you want HTTPS (Let’s Encrypt SSL).
- Update your
docker-compose.ymlwith any necessary changes to handle the domain and reverse proxy setup.
Step 7: Monitor and Maintain
Useful Docker commands for managing your app:
docker-compose ps– View running containersdocker-compose logs– View container logsdocker-compose down– Stop and remove containersdocker image prune– Clean up unused images
Remember to keep your server updated and secure. Set up firewalls (ufw), disable root SSH login, and consider using a monitoring service or uptime checker.
Conclusion
Deploying your web app to DigitalOcean using Docker Compose gives you a production-ready environment with full control and scalability. With minimal configuration, you can deploy updates, run multiple services, and manage containers efficiently.
Whether you’re launching a hobby project or scaling a business app, this setup strikes a great balance between simplicity and power , especially for developers who prefer to manage their infrastructure directly.
Disclaimer
Article written with the help of AI.
Read the full Disclaimer HERE