Docker Compose Basics¶
Docker Compose runs multi-container applications from a YAML file. In course labs, Compose is useful for starting a web app, database, and supporting services with one command.
Goal
Confirm the Docker Compose plugin is available, then run a small web server from a compose.yaml file.
1. Prerequisite¶
Complete Docker Setup on Ubuntu Server first.
Check Docker:
If docker compose version fails, install the Compose plugin:
2. Create a Compose Lab Folder¶
3. Create compose.yaml¶
Paste:
4. Start the Service¶
Check status:
Test locally on the server:
Expected: HTML from the Nginx welcome page.
5. Stop and Clean Up¶
Confirm no Compose containers remain:
6. Common Compose Commands¶
| Task | Command |
|---|---|
| Start services in foreground | docker compose up |
| Start services in background | docker compose up -d |
| Stop and remove services | docker compose down |
| View logs | docker compose logs |
| Follow logs | docker compose logs -f |
| Show service status | docker compose ps |
| Rebuild images | docker compose build |
7. Classroom Checkpoint¶
Record:
Troubleshooting¶
| Problem | Fix |
|---|---|
docker: permission denied | Use sudo or complete the Docker group step from the Docker setup page. |
| Port 8080 already in use | Change 8080:80 to another host port, such as 8081:80. |
| YAML parsing error | Check indentation. YAML uses spaces, not tabs. |
Next Step¶
You are ready to run containerized course labs.