本文由ilanniweb微信公众号提供友情赞助,首发于烂泥行天下
jenkins技术分享QQ群:571981257
前段时间写了有关wordpress迁移到docker和通过docker搭建nextclooud的文章,连接分别如下:《烂泥:wordpress迁移到docker》、《烂泥:个人网盘nextcloud的docker化搭建》。
因为这两个应用都是在同一台服务器上,而且都是通过docker-compose来启动应用的,所以这篇文章就来讲解下如何把wordpress和nextcloud集成到同一个docker-compose.yml文件中。
一、分析wordpress的docker-compose.yml文件
由《烂泥:wordpress迁移到docker》这篇文章,我们可以知道wordpress的docker-compose.yml文件内容如下:
vim docker-compose.yml
version: ‘2’
services:
mysqldb:
image: hub.c.163.com/library/mysql:5.5
container_name: ilanni_mysql
ports:
– “33033:3306”
volumes:
– ./data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: 123456
MYSQL_DATABASE: ilanni
MYSQL_USER: wwwilanni
MYSQL_PASSWORD: ilanni123
wordpress:
depends_on:
– mysqldb
image: hub.c.163.com/library/wordpress
container_name: ilanni_wordpress
ports:
– “80:80”
restart: always
environment:
WORDPRESS_DB_HOST: ilanni_mysql:3306
WORDPRESS_DB_NAME: ilanni
WORDPRESS_DB_USER: wwwilanni
WORDPRESS_DB_PASSWORD: ilanni123
volumes:
– ./wp-content/themes/xiu_ilanni:/var/www/html/wp-content/themes/xiu_ilanni
– ./wp-content/plugins:/var/www/html/wp-content/plugins
– ./wp-content/uploads:/var/www/html/wp-content/uploads
– ./favicon.ico:/var/www/html/favicon.ico
– ./alivv.txt:/var/www/html/alivv.txt
通过上述docker-compose.yml文件,我们可以很明显的看出wordpress使用了nginx和mysql这两个docker镜像。
而nginx镜像提供wordpress解析php的功能,mysql提供wordpress存储数据的功能。
如果我们要和nextcloud镜像进行集成的话,我们只需要把nginx镜像相关功能共享给nextcloud镜像即可。下面我们来看看nextcloud的docker-compose.yml文件。
二、分析nextcloud的docker-compose.yml文件
由《烂泥:个人网盘nextcloud的docker化搭建》这篇文章,我们可以知道nextcloud的docker-compose.yml文件内容如下:
vim docker-compose.yml
nextcloud-db:
image: mariadb
container_name: nextcloud_db
ports:
– “33034:3306”
volumes:
– ./mariadb:/var/lib/mysql
environment:
– MYSQL_ROOT_PASSWORD=123456
– MYSQL_DATABASE=nextcloud
– MYSQL_USER=wwwilanni
– MYSQL_PASSWORD=123456
nextcloud_web:
image: wonderfall/nextcloud
container_name: nextcloud_web
environment:
– UID=1000
– GID=1000
– UPLOAD_MAX_SIZE=10G
– APC_SHM_SIZE=128M
– OPCACHE_MEM_SIZE=128
– CRON_PERIOD=15m
– TZ=Aisa/Shanghai
– ADMIN_USER=admin
– ADMIN_PASSWORD=123456
– DOMAIN=pan.ilanni.com
– DB_TYPE=mysql
– DB_NAME=nextcloud
– DB_USER=wwwilanni
– DB_PASSWORD=123456
– DB_HOST=nextcloud-db:3306
volumes:
– ./nextcloud/data:/data
– ./nextcloud/config:/config
– ./nextcloud/apps:/apps2
– ./nextcloud/themes:/nextcloud/themes
links:
– nextcloud-db
nginx:
image: nginx:alpine
container_name: nginx
restart: always
ports:
– “80:80”
volumes: – ./pan.ilanni.com.conf:/etc/nginx/conf.d/pan.ilanni.com.conf
links:
– nextcloud_web
通过上述docker-compose.yml文件,我们可以很明显的看出nextcloud使用了nginx和mariadb这两个docker镜像。
而nginx镜像提供nextcloud反向代理的功能,mariadb提供nextcloud存储数据的功能。
如果我们要和wordpress镜像进行集成的话,我们只需要使用wordpress的docker-compose.yml文件中,nginx镜像的反向代理功能即可。
三、集成docker-compose.yml文件
根据第一章节和第二章节分析wordpress和nextcloud的docker-compose.yml文件可以知道,wordpress和nextcloud集成后的docker-compose.yml文件内容如下:
cat docker-compose.yml
wordpress_db:
image: mysql:latest
container_name: wordpress_db
restart: always
ports:
– “33033:3306”
volumes:
– ./data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: 123456
MYSQL_DATABASE: ilanni
MYSQL_USER: wwwilanni
MYSQL_PASSWORD: ilanni123
wordpress_php:
image: wordpress:fpm-alpine
container_name: wordpress_php
restart: always
environment:
WORDPRESS_DB_HOST: wordpress_db:3306
WORDPRESS_DB_NAME: ilanni
WORDPRESS_DB_USER: wwwilanni
WORDPRESS_DB_PASSWORD: ilanni123
volumes:
– ./wordpress:/var/www/html
links:
– wordpress_db
nextcloud-db:
image: mariadb:latest
container_name: nextcloud_db
restart: always
ports:
– “33034:3306”
volumes:
– ./mariadb:/var/lib/mysql
environment:
– MYSQL_ROOT_PASSWORD=123456
– MYSQL_DATABASE=nextcloud
– MYSQL_USER=wwwilanni
– MYSQL_PASSWORD=123456
nextcloud_web:
image: wonderfall/nextcloud
container_name: nextcloud_web
restart: always
ports:
– “8080:8888”
environment:
– UID=1000
– GID=1000
– UPLOAD_MAX_SIZE=10G
– APC_SHM_SIZE=128M
– OPCACHE_MEM_SIZE=128
– CRON_PERIOD=15m
– TZ=Aisa/Shanghai
– ADMIN_USER=admin
– ADMIN_PASSWORD=123456
– DOMAIN=pan.ilanni.com
– DB_TYPE=mysql
– DB_NAME=nextcloud
– DB_USER=wwwilanni
– DB_PASSWORD=123456
– DB_HOST=nextcloud-db:3306
volumes:
– ./nextcloud/data:/data
– ./nextcloud/config:/config
– ./nextcloud/apps:/apps2
– ./nextcloud/themes:/nextcloud/themes
links:
– nextcloud-db
nginx:
image: nginx:alpine
container_name: nginx
restart: always
ports:
– “80:80”
– “443:443”
volumes:
– ./wordpress:/var/www/html
– ./www.ilanni.com.conf:/etc/nginx/conf.d/www.ilanni.com.conf
– ./pan.ilanni.com.conf:/etc/nginx/conf.d/pan.ilanni.com.conf
– ./logs/:/var/log/nginx/
links:
– wordpress_php
– nextcloud_web
上述docker-compose.yml文件中,我们创建了wordpress和nextcloud相应的镜像和数据存储镜像,最后通过nginx镜像的links使wordpress和nextcloud镜像集成到一起。
这样wordpress和nextcloud访问入口,都是通过nginx镜像提供,然后nginx根据不同的域名,分发到其后端不同的应用上。
到此,有关wordpress镜像和nextcloud镜像通过docker-compose.yml集成的文章就已经全部结束。
未经允许不得转载:烂泥行天下 » 烂泥:docker-compose集成wordpres和nextcloud