This demo showcases the various capabilities of job containers in GitHub Actions, demonstrating real-world use cases and best practices. The workflow is designed to be educational and comprehensive while remaining accessible for audiences at different technical levels.
After running this demo, participants will understand:
- How to configure job containers in GitHub Actions
- The difference between job containers and service containers
- Container networking in GitHub Actions
- Best practices for using containers in CI/CD pipelines
- How to troubleshoot container-related issues
- Access to the GitHub repository with admin or write permissions
- GitHub Actions enabled on the repository
- Basic understanding of Docker containers (helpful but not required)
- Go to your GitHub repository
- Click on the "Actions" tab
- Look for "Job Containers Demo" in the workflow list
- Click "Run workflow" button
When triggering the workflow manually, you can choose:
- Environment: Select from development, staging, or production
- This demonstrates how input parameters work with containers
- Different environments may have different configurations
- Watch the workflow progress in real-time
- Each job runs in parallel (except where dependencies exist)
- Total execution time: approximately 5-8 minutes
"Today we're going to explore GitHub Actions job containers - a powerful feature that allows us to run our CI/CD jobs inside Docker containers. This provides consistency, isolation, and access to specific tools and environments."
Key Points to Mention:
- Containers ensure consistent environments across different runners
- They provide isolation and security
- Allow access to specific tools, languages, and configurations
What it demonstrates:
container:
image: node:18-alpine
env:
NODE_ENV: development
options: --cpus 1Explanation:
"Our first job shows the simplest container configuration. We're running inside a Node.js 18 Alpine Linux container. Notice how we can set environment variables and Docker options directly in the workflow."
Key Learning Points:
- Basic container syntax
- Environment variable injection
- Container resource limits
- How the runner mounts the workspace
What to Show:
- Point out the container image selection
- Explain environment variables
- Show the output displaying Node.js and system information
What it demonstrates:
container:
image: python:3.11-slim
services:
postgres:
image: postgres:15
options: --health-cmd pg_isready
redis:
image: redis:7-alpineExplanation:
"This job showcases service containers - additional containers that run alongside your main job container. Here we have PostgreSQL and Redis services that our Python application can connect to."
Key Learning Points:
- Service container configuration
- Health checks for services
- Container networking (automatic DNS resolution)
- Database connectivity patterns
What to Show:
- Explain the
servicessection - Point out health check configurations
- Show database connection and data insertion
- Demonstrate Redis caching functionality
What it demonstrates:
strategy:
matrix:
container_config:
- name: "Alpine Linux"
image: "alpine:latest"
- name: "Ubuntu"
image: "ubuntu:22.04"Explanation:
"Using matrix strategies with containers allows us to test across different operating systems and environments. This job runs the same steps in Alpine Linux, Ubuntu, and Amazon Linux containers."
Key Learning Points:
- Matrix strategies with containers
- Cross-platform testing
- Container options and configurations
- Package manager differences across distributions
What to Show:
- Explain matrix strategy syntax
- Point out different package installation commands
- Show OS-specific outputs
What it demonstrates:
container:
image: nginx:alpine
options: >-
--user root
--workdir /usr/share/nginx/html
credentials:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}Explanation:
"This job shows advanced container configuration including custom working directories, user settings, and how to authenticate with private registries."
Key Learning Points:
- Advanced container options
- Working directory customization
- User and permission management
- Private registry authentication (concept)
What to Show:
- Container customization options
- File system manipulation within containers
- Security considerations
What it demonstrates:
services:
web-server:
image: httpd:2.4-alpine
ports:
- 8080:80Explanation:
"Our final job explores container networking, showing how containers communicate with each other and how port mapping works in GitHub Actions."
Key Learning Points:
- Container-to-container networking
- Port mapping concepts
- DNS resolution between containers
- Network isolation and security
What to Show:
- Service connectivity by name
- Port mapping demonstration
- Network configuration details
- Without containers: Jobs run directly on the GitHub-hosted runner
- With containers: Jobs run inside a Docker container on the runner
- Benefits: Consistency, isolation, specific tool versions
- Run alongside your job container
- Provide databases, caches, or other services
- Automatically networked with job container
- Support health checks for reliability
- Containers can communicate by service name
- Port mapping for external access
- Automatic DNS resolution
- Isolated network environments
- Use specific image tags (not
latestin production) - Implement health checks for services
- Set appropriate resource limits
- Use official images when possible
- Secure credential management
- Ask Questions: "Who has used Docker before?" "What challenges have you faced with CI/CD environments?"
- Interactive Elements: Have attendees guess what will happen next
- Real-world Examples: Relate each concept to practical scenarios
Q: Why use containers instead of installing tools directly on the runner? A: Containers provide version consistency, faster setup (pre-built images), isolation between jobs, and easier local reproduction.
Q: How do containers affect job performance? A: There's a slight overhead for container startup, but this is usually offset by having pre-configured environments and parallel downloads.
Q: Can I use private Docker registries?
A: Yes! Use the credentials section with GitHub secrets for authentication.
Q: What's the difference between job containers and service containers? A: Job containers run your workflow steps, while service containers provide supporting services like databases.
- Check image name and tag spelling
- Verify registry accessibility
- Ensure credentials are correct (for private images)
- Verify service health checks pass
- Check service container logs
- Ensure correct hostname (use service name)
- Use
--user rootoption if needed - Check file system permissions
- Verify container user has necessary access
When the demo completes successfully, you should see:
- Job 1: Node.js version info and successful package installation
- Job 2: Database and Redis connectivity confirmation
- Job 3: Three parallel jobs showing different OS environments
- Job 4: Custom Nginx configuration and HTML serving
- Job 5: Network connectivity tests and container isolation info
Total runtime: ~5-8 minutes with all jobs running in parallel where possible.
- Modify the Node.js version in Job 1 and observe differences
- Add a new service container (e.g., MongoDB)
- Experiment with different base images
- Implement multi-stage container builds
- Add custom Dockerfile usage
- Integrate with container registries
- Add security scanning steps
- GitHub Actions Container Documentation
- Docker Hub Official Images
- GitHub Actions Best Practices
- Container Security Guidelines
Demo Duration: 15-20 minutes
Skill Level: Beginner to Intermediate
Prerequisites: Basic GitHub Actions knowledge helpful but not required