
Deploy a Project on GCE
1. Create a Virtual Machine
Use the Google Compute Engine service in Google Cloud to create a VM.
Recommended spec: e2-small — 2 vCPU, 2 GiB RAM, 20 GB Disk (~$14/month)
2. Connect to the VM via SSH
You can use the browser-based SSH from Google Cloud Console, or connect from your local machine.
Local SSH Setup
Step 1 — Generate an SSH key pair on your local machine:
ssh-keygen -t ed25519 -C "your@email.com"
Give the key a name (e.g. gce-dev-key) and leave the password blank.
This produces two files:
- –
gce-dev-key— private key (keep this on your machine) - –
gce-dev-key.pub— public key (add this to GCE)
Step 2 — Add the public key to Google Cloud:
- –Search "SSH" in the Google Cloud Console
- –Click SSH Keys
- –Paste the contents of
gce-dev-key.pub
The key is automatically added to every VM in the project, so you can connect to any VM with the same private key.
Step 3 — Connect:
ssh -i ~/.ssh/gce-dev-key <username>@<external_IP_of_VM>
3. Install Git and Docker on the VM
sudo apt-get update
# Install Git
sudo apt-get install -y git
git --version
# Install Docker
sudo apt install -y docker.io
docker --version
# Install Docker Compose
sudo apt install -y docker-compose
docker-compose --version
# Enable Docker on startup
sudo systemctl enable docker
# Allow your user to run Docker without sudo
sudo usermod -aG docker $USER
4. Restart the SSH Connection
Log out and reconnect so the Docker group membership takes effect.
5. Create a Project Folder
mkdir ~/project
6. Connect the VM to GitHub via SSH
Step 1 — Generate an SSH key pair on the VM:
cd ~/.ssh
ssh-keygen -t ed25519 -C "your@email.com"
Name the key github_key and leave the password blank.
Step 2 — Add the public key to GitHub:
Copy the contents of github_key.pub and paste it into:
GitHub → Profile Settings → SSH and GPG Keys → New SSH Key
Step 3 — Configure SSH to use this key for GitHub:
nano ~/.ssh/config
Paste the following:
# GitHub configuration
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/github_key
Step 4 — Test the connection:
ssh -T git@github.com
Expected output:
Hi <your-username>! You've successfully authenticated, but GitHub does not provide shell access.
7. Clone the Project Repository
cd ~/project
git clone git@github.com:<your-org>/<your-repo>.git
cd <your-repo>
8. Add Your Environment Variables
Create a .env file in the project root with the required environment variables.
9. Switch to the Correct Branch
git branch # check current branch
git checkout dev # switch to your target branch
git log # verify the latest commits
10. Start the Docker Project
export COMPOSE_HTTP_TIMEOUT=300
NODE_ENV=production docker-compose up -d --build
11. Verify Running Containers
docker ps
12. Check Application Logs
docker logs <container_id>
Next Steps
Once the project is running, you can set up a CI/CD pipeline using GitHub Actions to automate builds and deployments whenever you push to your target branch.