First Deployment: Hello World App¶
Progress: Module 1 of 4 → Page 3 of 3
Overview¶
You've got access to the server and understand the infrastructure. Now deploy your first application! We'll deploy a simple HTTP server that responds "Hello World" to demonstrate the complete deployment process.
Time: 15-20 minutes
Prerequisites Checklist¶
Before you start, make sure you have:
- Completed Lesson 1: Get Access
- Completed Lesson 2: Server Tour
- SSH access to the server working
- Basic familiarity with Git and GitHub
- A text editor for creating files
What You'll Deploy¶
We'll deploy a simple Node.js HTTP server:
// server.js
const http = require('http');
const server = http.createServer((req, res) => {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World!\n');
});
server.listen(3000, () => {
console.log('Server running on port 3000');
});
This server: - Listens on port 3000 - Responds to any request with "Hello World!" - Takes about 2 minutes to deploy
Part 1: Create Your Application¶
Step 1: Create GitHub Repository¶
Your application needs to be on GitHub so GitHub Actions can deploy it.
- Log in to GitHub: https://github.com
- Create new repository:
- Name:
hello-world-app - Description: "First EgyGeeks deployment"
- Visibility: Public (or Private if preferred)
- Initialize with: README.md
-
Click "Create repository"
-
Clone locally:
Ask AI for Help
Copy this prompt to Claude or ChatGPT:
Step 2: Create Application Files¶
Create the application structure:
1. Create package.json:
cat > package.json << 'EOF'
{
"name": "hello-world-app",
"version": "1.0.0",
"description": "First EgyGeeks deployment",
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"dependencies": {}
}
EOF
2. Create server.js:
cat > server.js << 'EOF'
const http = require('http');
const server = http.createServer((req, res) => {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World!\n');
});
const PORT = process.env.PORT || 3000;
server.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});
EOF
3. Create .gitignore:
Step 3: Create Dockerfile¶
Create Dockerfile to package your app:
cat > Dockerfile << 'EOF'
# Use official Node.js runtime
FROM node:18-alpine
# Set working directory
WORKDIR /app
# Copy application files
COPY package.json server.js ./
# No dependencies needed, but install if any exist
RUN npm install || true
# Expose port
EXPOSE 3000
# Start application
CMD ["npm", "start"]
EOF
Step 4: Create Docker Compose¶
Create docker-compose.yml for local testing:
cat > docker-compose.yml << 'EOF'
version: '3'
services:
app:
build: .
container_name: hello-world-app
ports:
- "3000:3000"
environment:
- NODE_ENV=production
EOF
Step 5: Commit and Push¶
Save your code to GitHub:
# Stage files
git add .
# Commit
git commit -m "feat: initial hello world app"
# Push to GitHub
git push origin main
Verify: Go to GitHub and confirm all files are uploaded.
Part 2: Setup Deployment¶
Step 1: Create GitHub Actions Workflow¶
Create the deployment automation:
# Create workflow directory
mkdir -p .github/workflows
# Create deploy workflow
cat > .github/workflows/deploy.yml << 'EOF'
name: Deploy to EgyGeeks
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build Docker image
run: docker build -t hello-world-app:latest .
- name: Deploy to server
env:
DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }}
SERVER_IP: ${{ secrets.SERVER_IP }}
SERVER_USER: ${{ secrets.SERVER_USER }}
run: |
mkdir -p ~/.ssh
echo "$DEPLOY_KEY" > ~/.ssh/deploy_key
chmod 600 ~/.ssh/deploy_key
ssh -i ~/.ssh/deploy_key -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP 'cd /opt/apps/hello-world-app && git pull origin main && docker-compose up -d --build'
EOF
Step 2: Add Secrets to GitHub¶
GitHub Actions needs credentials to deploy. Ask your admin to provide: - DEPLOY_KEY: SSH private key (for authentication) - SERVER_IP: Server IP address (e.g., 50.3.85.110) - SERVER_USER: SSH username
Then:
- Go to GitHub repository
- Settings → Secrets and variables → Actions
- Click "New repository secret"
- Add each secret:
- Name:
DEPLOY_KEY - Value: (paste SSH private key)
- Click "Add secret"
- Repeat for
SERVER_IPandSERVER_USER
Ask AI for Help
Copy this prompt to Claude or ChatGPT:
I need to add deployment secrets to my GitHub repository for the hello-world-app.
Walk me through:
1. How to access the Secrets settings in my GitHub repository
2. Adding three secrets: DEPLOY_KEY, SERVER_IP, and SERVER_USER
3. Security best practices for storing SSH keys in GitHub
4. How to verify the secrets are set correctly
5. What to do if GitHub Actions can't access the secrets
My repository: https://github.com/[YOUR_USERNAME]/hello-world-app
Step 3: Commit Workflow¶
Save the workflow:
git add .github/workflows/deploy.yml
git commit -m "ci: add deployment workflow"
git push origin main
Part 3: Prepare Server¶
Step 1: Create App Directory¶
SSH to the server and prepare the directory:
# SSH to server
ssh username@50.3.85.110
# Create app directory
sudo mkdir -p /opt/apps/hello-world-app
sudo chown $USER:$USER /opt/apps/hello-world-app
# Navigate to it
cd /opt/apps/hello-world-app
# Initialize Git repository
git init
git remote add origin https://github.com/YOUR_USERNAME/hello-world-app.git
# Pull initial code
git pull origin main
Step 2: Configure Traefik¶
Create a docker-compose.yml on the server with Traefik configuration:
cat > /opt/apps/hello-world-app/docker-compose.yml << 'EOF'
version: '3'
services:
hello-world-app:
build: .
container_name: hello-world-app
environment:
- NODE_ENV=production
labels:
- "traefik.enable=true"
- "traefik.http.routers.hello-world-app.rule=PathPrefix(`/hello-world`)"
- "traefik.http.services.hello-world-app.loadbalancer.server.port=3000"
networks:
- traefik-network
networks:
traefik-network:
external: true
name: traefik
EOF
Step 3: Create Network (if needed)¶
Traefik needs a network to communicate with your app:
# Check if network exists
docker network ls | grep traefik
# If not, create it (usually already exists)
docker network create traefik
Step 4: Start Application Manually¶
Test it before automating:
# Navigate to app directory
cd /opt/apps/hello-world-app
# Build and start
docker-compose up -d --build
# Check status
docker-compose ps
# View logs
docker-compose logs -f
# Test locally on server
curl http://localhost/hello-world
# Expected output: "Hello World!"
Part 4: Test Your Deployment¶
Step 1: Verify Container is Running¶
# SSH to server
ssh username@50.3.85.110
# Check running containers
docker ps
# Should show: hello-world-app running
# Check logs
docker logs hello-world-app
# Expected output: "Server running on port 3000"
Step 2: Access Your App¶
Open your browser and visit:
You should see: Hello World!
Can't Access Your App? Ask AI
If you get errors or can't see your app, copy this debugging prompt:
I deployed a Node.js app to http://50.3.85.110/hello-world but I can't access it.
Here's my setup:
- Container name: hello-world-app
- Traefik labels in docker-compose.yml:
traefik.http.routers.hello-world.rule=PathPrefix(`/hello-world`)
traefik.http.services.hello-world.loadbalancer.server.port=3000
When I run `docker ps`:
[paste your output here]
When I run `docker logs hello-world-app`:
[paste your output here]
When I visit the URL I see:
[describe what you see - 404, blank page, error, etc.]
What's wrong and how do I fix it?
Step 3: Make a Change (Test Redeployment)¶
Verify the automatic deployment works:
# On your local machine, edit server.js
# Change: res.end('Hello World!\n');
# To: res.end('Hello World from [Your Name]!\n');
# Commit and push
git add server.js
git commit -m "feat: personalize greeting"
git push origin main
- Check GitHub Actions (Actions tab)
- Wait for deployment to complete (2-3 minutes)
- Refresh browser to see new message
Verification Steps¶
Complete these checks to verify your deployment:
- GitHub repository created with all files
- GitHub Actions workflow is configured
- SSH secrets are added to GitHub
- App directory created on server
-
docker-compose upworks locally - Container is running on server:
docker ps - You can access app at
http://50.3.85.110/hello-world - App shows "Hello World!" in browser
- Automatic redeployment works after git push
Troubleshooting¶
App Not Accessible¶
Problem: Browser shows "404 Not Found" or connection refused
Solutions: 1. Check container is running: docker ps 2. Check logs for errors: docker logs hello-world-app 3. Verify Traefik routing: curl -H "Host: localhost" http://50.3.85.110/hello-world 4. Check docker-compose labels are correct 5. Restart container: docker-compose restart
Having Issues? Debug with AI
My hello-world-app is not accessible at http://50.3.85.110/hello-world
When I visit the URL I see:
[404 error / connection refused / blank page / other - describe exactly]
Output from `docker ps`:
[paste output here]
Output from `docker logs hello-world-app`:
[paste last 30 lines here]
Output from `docker logs traefik | grep hello-world`:
[paste output here]
My docker-compose.yml Traefik labels:
[paste the labels section from your docker-compose.yml]
Help me diagnose why the app is not accessible and fix the routing issue.
Docker Build Fails¶
Problem: docker-compose up -d --build shows errors
Solutions: 1. Check Dockerfile syntax: docker build . 2. Verify Node.js base image exists: docker pull node:18-alpine 3. Check for typos in Dockerfile 4. View full logs: docker-compose up --build (without -d)
Having Issues? Debug with AI
My Docker build is failing for the hello-world-app.
Error message when running `docker-compose up -d --build`:
[paste the complete error output here]
My Dockerfile:
[paste your complete Dockerfile here]
My docker-compose.yml:
[paste your complete docker-compose.yml here]
Output from `docker images | grep hello-world`:
[paste output here]
Help me identify what's wrong with my Docker configuration and how to fix it.
GitHub Actions Not Deploying¶
Problem: Workflow runs but doesn't update server
Solutions: 1. Check GitHub Actions logs (Actions tab) 2. Verify secrets are set: Settings → Secrets 3. Check SSH key permissions: ls -la ~/.ssh/deploy_key (should be 600) 4. Test SSH manually: ssh -i ~/.ssh/deploy_key user@50.3.85.110
Having Issues? Debug with AI
My GitHub Actions workflow is not deploying the hello-world-app successfully.
Repository: https://github.com/[YOUR_USERNAME]/hello-world-app
Workflow status: [passed/failed/running]
Error from GitHub Actions logs (Actions tab):
[paste the error section from the failed job]
My .github/workflows/deploy.yml file:
[paste your complete workflow file]
Secrets configured in repository:
- DEPLOY_KEY: [yes/no]
- SERVER_IP: [yes/no]
- SERVER_USER: [yes/no]
When I manually SSH to the server:
[works fine / shows error - paste error if any]
Help me fix the GitHub Actions deployment workflow.
Traefik Not Routing¶
Problem: Container running but can't access at /hello-world
Solutions: 1. Verify Traefik is running: docker ps | grep traefik 2. Check docker-compose labels are formatted correctly 3. Restart Traefik: docker-compose restart traefik 4. Check Traefik logs: docker logs traefik 5. Verify network exists: docker network ls | grep traefik
Having Issues? Debug with AI
Traefik is not routing traffic to my hello-world-app correctly.
Container status from `docker ps`:
[paste output showing both traefik and hello-world-app containers]
Output from `docker network ls`:
[paste output here]
Output from `docker logs traefik | tail -50`:
[paste last 50 lines of Traefik logs]
My docker-compose.yml labels section:
[paste the complete labels section from your docker-compose.yml]
When I run `curl http://localhost:3000` on the server:
[paste result - does the app respond directly?]
When I run `curl http://localhost/hello-world` on the server:
[paste result - 404/error/success?]
Help me fix the Traefik routing configuration for PathPrefix `/hello-world`.
Summary¶
You've successfully: - Created a Node.js application - Set up GitHub repository - Configured GitHub Actions for automatic deployment - Deployed to the EgyGeeks server - Verified the app is running and accessible - Tested automatic redeployment
Congratulations! You've completed Module 1 and deployed your first app!
What's Next?¶
Now that you can deploy applications, let's learn about deploying different types of apps.
Next Module: Module 2: Deploying Apps
Module Overview: Back to Module 1
Need Help?¶
Quick Reference¶
# Local testing
docker-compose up -d --build
docker-compose ps
docker-compose logs -f
docker-compose down
# Server deployment
ssh username@50.3.85.110
cd /opt/apps/hello-world-app
docker-compose ps
docker logs hello-world-app
docker-compose restart
# View app
curl http://localhost/hello-world # On server
# Browser: http://50.3.85.110/hello-world
Common Commands¶
| Task | Command |
|---|---|
| Check if container running | docker ps |
| View container logs | docker logs hello-world-app |
| Restart container | docker-compose restart |
| Stop container | docker-compose down |
| Rebuild and start | docker-compose up -d --build |
| View app status | docker-compose ps |
Still Stuck?¶
Having Issues? Debug with AI
I'm stuck deploying my hello-world-app. Here's my situation:
Problem: [describe your specific issue]
What I've tried:
- [list steps you've already attempted]
Current status:
- GitHub Actions workflow status: [passed/failed/running]
- Container running: [yes/no - paste `docker ps` output]
- Traefik status: [paste `docker ps | grep traefik` output]
Logs from `docker logs hello-world-app`:
[paste last 20 lines here]
GitHub Actions logs (if deployment failed):
[paste error section here]
When I visit http://50.3.85.110/hello-world I see:
[describe exactly what happens]
Help me diagnose and fix this issue step by step.
Resources¶
Tags: Deployment, Hello World, Docker, GitHub Actions, First App
Module: 1 of 4 | Page: 3 of 3 | Module Complete!