有了前面的準備,後續服務就超級簡單了,比如我們現在要創建一個博客服務,只需要創建一個 blog 項目在 compose.yaml 中輸入下述 compose 設定
networks:
ingress_intranet:
external: true
services:
db:
image: ${IMAGE_OF_DB}
restart: always
environment:
- TZ=Asia/Shanghai
- MYSQL_ROOT_PASSWORD=123
- MYSQL_DATABASE=wordpress
volumes:
- /opt/data/blog/mysql:/var/lib/mysql
blog:
image: ${IMAGE_OF_WORDPRESS}
restart: always
environment:
- WORDPRESS_DB_HOST=db
- WORDPRESS_DB_USER=root
- WORDPRESS_DB_PASSWORD=123
- WORDPRESS_DB_NAME=wordpress
- FORCE_SSL_ADMIN=false
volumes:
- /opt/data/blog/wordpress/plugins:/var/www/html/wp-content/plugins
- /opt/data/blog/wordpress/themes:/var/www/html/wp-content/themes
- /opt/data/blog/wordpress/uploads:/var/www/html/wp-content/uploads
networks:
default:
ingress_intranet:
ipv4_address: ${IP_OF_INGRESS}
.env 環境設定如下
IMAGE_OF_DB="mariadb:10.5.9"
IMAGE_OF_WORDPRESS="wordpress:6.1"
IP_OF_INGRESS="172.20.1.10"
執行 docker-compose -d 就部署好了:
- services db 創建好了博客需要的數據庫
- services blog 創建好了博客,記得去網關入口將域名反代到這個 service 的 80 端口
如此就又水一篇文章,docker compose 就是如此容易與簡單