Introduction
Docker Compose is a tool for defining and running multi-container applications. It is the key to unlocking a streamlined and efficient development and deployment experience.
1 Dockerfile → 1 Image Build Docker Run → Run 1 Container with ENTRYPOINT & CMD Docker Compose → Run multiple containers with 1 YAML-formatted file Installation
Template
“Docker-compose.yml” has versions: 1,2,3...
Jekull Template
Wordpress Template
Ghost Template
Secrets in Compose
Bởi vì trong Compose có rất nhiều biến môi trường, nên lưu trữ Secrets là điều cần thiết, nhất là khi cần phải sử dụng với Github.
Commands
# build, run all containers
docker compose up
# stop and remove all containers
docker compose down
# remove all images as well
docker compose down -rmi
# list all container is compose
docker compose ps
Default Nginx + Apache Template
Use Compose to build Custom Nginx Image + Apache with HTML code
Nginx Config
This nginx.conf configures Nginx as a reverse proxy. Here’s what it does:
For all requests (location /), it forwards (proxies) them to a backend service named web (which is apache). It sets several headers to preserve the original client information (Host, X-Real-IP, X-Forwarded-For, X-Forwarded-Host). Disables automatic proxy redirects. Compared to the default config in the official Nginx image:
The default config serves static files from /usr/share/nginx/html and does not proxy requests. The default does not set up any proxy headers or backend forwarding. In summary: This config turns Nginx into a reverse proxy for a backend service, while the default config just serves static files.