This project demonstrates Docker best practices with a simple multi-container application using Docker Compose. The application consists of three containers:
- Frontend: A simple Nginx web server serving static HTML, CSS, and JavaScript
- Backend: A Node.js/Express API server
- Database: A PostgreSQL database for data persistence
The focus of this project is on Docker concepts rather than complex application logic.
- Multi-stage Dockerfile builds
- Docker Compose for multi-container orchestration
- Volume management for data persistence
- Container networking
- Environment variables and secrets management
- Docker best practices
docker-learning-project/
├── docker-compose.yml # Define and configure all services
├── .env # Environment variables for docker-compose
├── README.md # Main project documentation
├── frontend/ # Nginx static web server
├── backend/ # Node.js API server
└── database/ # PostgreSQL database
- Clone this repository
- Make sure Docker and Docker Compose are installed
- Run
docker-compose up -d
- Access the application at http://localhost:8080
The application is a simple message board where users can:
- View all messages
- Add new messages
This simplicity allows us to focus on Docker concepts rather than complex application logic.
Containers are lightweight, standalone, executable packages that include everything needed to run an application. In this project, we have three containers that work together but remain isolated from each other.
Docker images are read-only templates used to create containers. Each component has its own Dockerfile that defines how to build its image.
Volumes are used for data persistence. We use volumes for:
- PostgreSQL data: ensures messages are preserved even if the container is removed
- Backend logs: preserves log data across container restarts
Containers communicate with each other through Docker networks. We use:
- frontend-network: connects the frontend and backend
- backend-network: connects the backend and database
Environment variables are used to configure containers without modifying their code. We use a .env
file and pass variables through Docker Compose.
Docker Compose is a tool for defining and running multi-container Docker applications. Our docker-compose.yml
file defines all three services and their relationships.