docker-compose 编排 lnmp 集群

1、docker-compose.yml ⽂件
[root@doc lnmp]# vim docker-compose.yml
version: '2'
volumes:
mysql-conf:
php-conf:
networks:
lnmp_net:
external: true
services:
nginx:
image: nginx
container_name: nginx-lnmp
hostname: nginx-lnmp
privileged: true
ports:
- 90:80
volumes:
-
/root/lnmp/nginx/html/:/usr/share/nginx/html/:rw
-
/root/lnmp/nginx/conf.d/:/etc/nginx/conf.d/:rw- /root/lnmp/nginx/logs/:/var/log/nginx/:rw
restart: always
networks:
- lnmp_net
php:
image: php:7.3.29-fpm
container_name: php-lnmp
hostname: php-lnmp
privileged: true
volumes:
- /root/lnmp/nginx/html/:/var/www/html/:rw
- php-conf:/usr/local/etc/php
volumes_from:
- mysql
restart: always
networks:
- lnmp_net
mysql:
image: mysql:5.6
container_name: mysql-lnmp
ports:
- 3306:3306
privileged: true
volumes:
- /var/lib/mysql
- /root/lnmp/mysql/data/:/var/lib/mysql/:rw2、⼯程⽬录结构树状图
- mysql-conf:/etc/mysql/
restart: always
networks:
- lnmp_net
environment:
MYSQL_ROOT_PASSWORD: "123456"
[root@doc lnmp]# tree ./
./
"## docker-compose.yml
"## mysql
$ %## data
"## mysql-conf
$ "## conf.d
"## nginx
$ "## conf.d
$ "## html
$ $ "## index.html
$ $ "## testa.php
$ $ "## testb.php
$ $ %## wordpress
$ %## logs
%## php-conf
"## conf.d
$ "## docker-php-ext-pdo_mysql.ini3、修改并导⼊配置⽂件
(1)nginx 配置⽂件
$ %## docker-php-ext-sodium.ini
"## php.ini
"## php.ini-development
%## php.ini-production
[root@doc lnmp]# vim nginx/conf.d/default.conf
server {
listen 80;
root /usr/share/nginx/html;
index index.html index.htm index.php;
# redirect server error pages to the static
page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location / {
index index.html index.htm index.php ;(2)导⼊ mysql 和 php 的配置⽂件到容器内
try_files $uri $uri/ /index.php?
$query_string;
autoindex on;
}
location ~ \.php$ {
fastcgi_pass php-lnmp:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param PATH_INFO
$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME
/var/www/html/$fastcgi_script_name;
}
}
[root@doc lnmp]# mv mysql-conf/*
/var/lib/docker/volumes/lnmp_mysql-conf/_data/
[root@doc lnmp]# mv php-conf/*
/var/lib/docker/volumes/lnmp_php-conf/_data/(3)php 容器安装 mysql 扩展插件
[root@doc lnmp]# docker compose exec php bash
root@php-lnmp:/var/www/html# docker-php-ext
install pdo_mysql
root@php-lnmp:/var/www/html# docker-php-ext
install mysqli
root@php-lnmp:/var/www/html#
exit
[root@doc lnmp]# docker compose restart php
[+] Restarting 1/1
✔ Container php-lnmp Started
0.3s
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值