Deploying Your Docker Application on Cloud VMs (Azure & GCP)
May 23, 2025
•4 minute read•58 views
In the previous blog, I wrote a bit about containerizing applications using Docker and orchestrate them with Docker Compose.
While local containers are a good way to start learning, the world can only see your creation once you take your containers to the clouds.
In this guide, we'll deploy Dockerized applications on Virtual Machines (VMs) provisioned on Azure and Google Cloud Platform (GCP).
No matter where you deploy — the underlying process is similar:
Get a VM → SSH into it → Install Docker → Run your app.
Step 1: Provision a Virtual Machine
1.1 Create an Azure VM
Go to Azure Portal.
Navigate: Virtual Machines → Create → Azure Virtual Machine.
Choose:
Image: Ubuntu 22.04 LTS
Size: B1s (small app) / larger as needed
Authentication: SSH Key (Recommended)
Inbound Ports: Allow SSH (22)
Finalize and launch the VM.
Note down the Public IP Address.
Azure Tip: Create a new Resource Group for clean organization.
1.2 Create a GCP VM Instance
Go to Google Cloud Console.
Navigate: Compute Engine → VM Instances → Create Instance.
Choose:
Machine Image: Ubuntu 22.04 LTS
Machine Type: e2-micro (small app) / larger if needed
Authentication: Use SSH Key (generate or upload your own)
Firewall Rules: Allow HTTP and HTTPS traffic
Finalize and launch the instance.
Note the External IP Address.
GCP Tip: e2-micro instances are free tier eligible in some regions.
Step 2: SSH Into Your Virtual Machine
From your local machine, connect to your VM:
ssh -i /path/to/your/private-key username@public-ip
Replace
username
with your VM's username (defaultazureuser
,ubuntu
, or custom).Replace
public-ip
with the VM’s external IP address.
Example:
ssh -i ~/.ssh/cloud_vm_key ubuntu@34.1xx.9x.12
If needed, fix SSH key permissions:
chmod 600 /path/to/your/private-key
Step 3: Set Up Docker on the VM
Once inside the VM, let's prepare it for containers.
3.1 Update System Packages
sudo apt update
sudo apt upgrade -y
3.2 Install Docker
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
Add your user to the Docker group:
sudo usermod -aG docker $USER
newgrp docker
Verify:
docker --version
3.3 Install Docker Compose
sudo apt install docker-compose -y
Verify:
docker-compose --version
Step 4: Transfer and Deploy Your Application
You can either SCP your code or git clone it directly.
4.1 Transfer Code via SCP
From your local machine:
scp -i /path/to/private-key -r ./your-project-folder username@public-ip:/home/username/
4.2 Clone Code via Git
Inside your VM:
git clone https://github.com/yourusername/yourproject.git
cd yourproject
4.3 Run Docker Compose
Inside your project directory:
docker-compose up -d
Your containers will start, detached in the background.
Step 5: Open Firewall Ports
Even if your application is running, you need to allow traffic to reach it.
Depending on your cloud provider:
Azure:
Go to Networking → Inbound Port Rules.
Add rules to allow TCP ports 80 (HTTP) and 443 (HTTPS).
GCP:
Go to VPC Network → Firewall.
Create a rule to allow incoming traffic on ports 80, 443.
(Optional) If you are running on a different port (like 3000 or 8080), open those too.
(Optional) Step 6: Add a Reverse Proxy and SSL
For production deployments, it's a good practice to put Nginx in front of your app.
Install Nginx:
sudo apt install nginx -y
Set up a simple reverse proxy in /etc/nginx/sites-available/default
:
server {
listen 80;
server_name your_domain.com;
location / {
proxy_pass http://localhost:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
Restart Nginx:
sudo systemctl restart nginx
(Optional) Get SSL certificates using Let's Encrypt:
sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d yourdomain.com
Step 7: Ensure Docker Containers Restart on Reboot
Modify your docker-compose.yml
:
restart: always
Or use:
docker update --restart=always <container_id>
This ensures that your app comes back online automatically if your VM reboots.
Troubleshooting Tips
SSH not working?
- Verify VM's external IP and firewall settings.
Docker not found?
- Ensure installation steps completed without errors.
App not accessible publicly?
- Double-check firewall rules and container port mappings.
Permission denied (publickey)?
- Check your SSH key permissions.
Conclusion
In this blog, we deployed our Dockerized app on cloud VMs — regardless of whether it was Azure or GCP.
You now know how to:
Provision a clean cloud VM
SSH and set it up
Install Docker and Docker Compose
Run your containers in production
Securely expose your app to the world
This workflow is industry-standard, forming the base for real-world production deployments.
✨ Pro Tip:
Next time, instead of manually SSHing and deploying, we can automate all of this using Ansible, Terraform, and CI/CD pipelines.