Your cart is currently empty!
Drone CI with Docker Compose – Beginner’s Guide π
What is Drone CI?
Drone is a modern Continuous Integration/Continuous Deployment (CI/CD) platform that uses Docker containers to run your build and deployment steps. It’s lightweight, easy to set up, and works great with Docker Compose.
Prerequisites
- Docker installed on your system
- Git repository for your project
- Basic understanding of Docker and Docker Compose
Step 1: Setting Up Your Project Structure
Create a basic project structure:
your-project/
βββ .drone.yml # Drone configuration
βββ docker-compose.yml # Your application services
βββ server/ # Backend code
βββ ClientApp/ # Frontend code
Step 2: Creating docker-compose.yml
Here’s a simple example:
version: '3.8'
name: your-app
services:
backend:
build:
context: ./server
dockerfile: Dockerfile
volumes:
- ./server/uploads:/app/uploads
restart: always
frontend:
build:
context: ./ClientApp
dockerfile: Dockerfile
ports:
- "80:80"
restart: always
volumes:
# Regular named volumes are managed by Docker
app_data:
networks:
default:
name: your-app-network
Step 3: Creating .drone.yml
Here’s a basic Drone configuration:
kind: pipeline
type: docker
name: deploy
trigger:
branch:
- prod
event:
- push
- manual
steps:
- name: debug-info
image: docker:dind
volumes:
- name: docker-socket
path: /var/run/docker.sock
commands:
- pwd
- ls -la
- docker version
- docker info
- docker compose version
- name: cleanup
image: docker:dind
volumes:
- name: docker-socket
path: /var/run/docker.sock
commands:
- echo "Stopping existing containers..."
- docker ps -q --filter name=your-app_ | xargs -r docker stop
- docker compose down
- sleep 5
- name: deploy
image: docker:dind
volumes:
- name: docker-socket
path: /var/run/docker.sock
commands:
- docker compose pull
- docker compose down --timeout 30 --remove-orphans
- docker compose up -d --build --force-recreate
- docker compose ps
volumes:
- name: docker-socket
host:
path: /var/run/docker.sock
Step 4: Important Notes
Volume Management
- Use regular named volumes in docker-compose.yml
- Don’t use external volumes unless absolutely necessary
- Let Docker manage the volume lifecycle
Deployment Steps
docker compose pull
Β – Gets latest imagesdocker compose down
Β – Stops and removes containersdocker compose up
Β – Starts containers with new images
Common Pitfalls to Avoid
- Don’t use external volumes unless you know what you’re doing
- Always include cleanup steps before deployment
- Use health checks for services that need them
- Keep your configuration simple and straightforward
Step 5: Testing Your Setup
- Push your changes to your repository
- Drone should automatically trigger a build
- Check the Drone dashboard for build status
- Verify your application is running correctly
Troubleshooting
Common Issues
- Volume not found: Make sure you’re using regular named volumes
- Build fails: Check your Dockerfile and docker-compose.yml
- Deployment fails: Verify your cleanup steps are working
Debugging Tips
- Use the debug-info step to check environment
- AddΒ
ls -la
Β commands to see file structure - Check Docker logs for container issues
Best Practices
- Keep your configuration simple
- Use health checks for critical services
- Implement proper cleanup steps
- Test your pipeline thoroughly
- Use secrets for sensitive information
Next Steps
- Add testing steps
- Implement staging environments
- Add deployment notifications
- Set up monitoring
Remember: Start simple and add complexity only when needed! π
by
Tags:
Leave a Reply