This repository contains a demo project created as part of my DevOps studies in the TechWorld with Nana – DevOps Bootcamp.
https://www.techworld-with-nana.com/devops-bootcamp
Demo Project: Deploy Docker application on a server with Docker Compose
Technologies used: Docker, Nexus, Node.js, MongoDB, MongoExpress
Project Description:
- Copy Docker-compose file to remote server
- Login to private Docker registry on remote server to fetch our app image
- Start our application container with MongoDB and
- MongoExpress services using docker compose
Create Docker repository on Nexus and push an app image to it (complete all the steps):
https://github.com/explicit-logic/docker-module-7.5
Important: On Apple Silicon, add the
--platform linux/amd64flag to thedocker buildcommand to ensure compatibility with the remote Linux server
docker build --platform linux/amd64 -t my-app:1.0 .Note: Replace
<DROPLET_IP>and<NEXUS_DROPLET_IP>with your actual IP addresses throughout this guide.
Create a new DigitalOcean droplet with the following specifications:
- OS: Ubuntu (latest LTS recommended)
- RAM: 2GB minimum
- SSH Key: Attach your public SSH key during creation
Connect to the droplet as root:
ssh root@<DROPLET_IP>For security best practice, create a dedicated user for running the application:
adduser app
usermod -aG sudo appInstall Docker Engine and Docker Compose on the server:
Reference: Installing Docker on Ubuntu
# Update package index and upgrade existing packages
apt update
apt upgrade -y
# Install prerequisites
apt install -y ca-certificates curl gnupg lsb-release
# Add Docker's official GPG key
mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
# Set up Docker repository
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
# Install Docker Compose standalone
curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
# Verify installation
docker --version
docker-compose --versionAdd the app user to the docker group to allow it to run Docker commands without sudo:
usermod -aG docker appNote: The user will need to log out and back in for the group membership to take effect.
Configure Docker to allow connections to your insecure Nexus registry:
vim /etc/docker/daemon.jsonAdd the following configuration:
{
"insecure-registries": ["<NEXUS_DROPLET_IP>:8083"]
}Security Note: This configuration allows unencrypted connections to Nexus. For production environments, consider using TLS certificates.
Restart Docker to apply the changes:
systemctl restart dockerVerify Docker is running:
systemctl status dockerSet up SSH access for the app user:
# Switch to app user
su - app
# Create .ssh directory with proper permissions
mkdir -p ~/.ssh
chmod 700 ~/.ssh
# Create and edit authorized_keys file
vim ~/.ssh/authorized_keysPaste your public SSH key into authorized_keys, then set proper permissions:
chmod 600 ~/.ssh/authorized_keys
exitVerify SSH access works:
ssh app@<DROPLET_IP>If successful, disconnect and continue from your local machine.
On your local machine, modify the docker-compose.yaml file to include your application service.
Add the following service configuration:
my-app:
image: <NEXUS_DROPLET_IP>:8083/my-app:1.0
ports:
- 3000:3000
env_file:
- .envTransfer the docker-compose.yaml file to the remote server:
scp docker-compose.yaml app@<DROPLET_IP>:/home/appSSH into the server as the app user and create the .env file:
ssh app@<DROPLET_IP>
vim .envAdd the following environment variables:
MONGO_DB_HOST=mongodb
MONGO_DB_USERNAME=admin
MONGO_DB_PASSWORD=passwordSecurity Note: In production, use strong passwords and consider using secrets management solutions.
Log in to your private Nexus Docker registry:
docker login <NEXUS_DROPLET_IP>:8083When prompted, enter the credentials created in the prerequisite steps:
- Username:
docker - Password:
pass
You should see a Login Succeeded message upon successful authentication.
Start all services using Docker Compose:
docker compose up -dTip: Use the
-dflag to run containers in detached mode (background).
View logs to verify the application is running correctly:
docker compose logs -fAccess your application at http://<DROPLET_IP>:3000

