文件部署准备
创建文件夹 mkdir docker/lnmp
创建文件 vim docker-compose.yml
version: '3.0'
services:
mysql:
image: mysql:5.7
container_name: mysql
command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
restart: always
environment:
MYSQL_ROOT_PASSWORD: westos
MYSQL_DATABASE: sql1
MYSQL_USER: westos
MYSQL_PASSWORD: westos
ports:
- "3306:3306"
volumes:
- ${PWD}/mysql:/var/lib/mysql
php:
image: php:8.0-fpm
container_name: php
restart: always
ports:
- "9000:9000"
volumes:
- ${PWD}/html:/var/www/html
nginx:
image: nginx:latest
container_name: nginx
restart: always
ports:
- "80:80"
- "443:443"
volumes:
- ${PWD}/html:/var/www/html
- ${PWD}/nginx/conf.d:/etc/nginx/conf.d
- ${PWD}/nginx/ssl:/etc/nginx/ssl
phpmyadmin:
image: phpmyadmin/phpmyadmin
environment:
PMA_HOST: mysql
PMA_PORT: 3306
PMA_ARBITRARY: 1
ports:
- "8080:80"
restart: always
创建ngixn虚拟主机配置文件
在新建的文件夹中创建一个名为“nginx”文件夹,再新建一个“conf.d”文件夹,在该文件夹中创建一个名为“default.conf”的文件,并添加以下内容:
server
{
listen 80 default_server reuseport;
#listen [::]:80 default_server ipv6only=on;
server_name _;
root /var/www/html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location /phpmyadmin {
allow 192.168.0.0/16;
deny all;
alias /usr/share/phpmyadmin/;
index index.php;
try_files $uri $uri/ =404;
location ~ \.php$ {
fastcgi_param MYSQL_HOST mysql;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /usr/share/phpmyadmin$fastcgi_script_name;
fastcgi_param PHP_VALUE "upload_max_filesize=128M \n post_max_size=128M";
}
}
location ~ \.php$ {
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~ /\.ht {
deny all;
}
创建html文件夹
在新建的文件夹中创建一个名为“html”的文件夹,该文件夹下可以放置你自己的网站文件
启动容器
运行yml文件
在命令行中进入到yml文件所在的目录中,输入以下命令启动容器:
docker-compose up -d
等待容器启动完成,即可在浏览器中输入你的域名访问网站,并使用“your_domain_name/phpmyadmin”访问phpMyAdmin进行数据库管理。
在windows中可以使用IP进行访问。
文件结构
.
├── docker-compose.yml
├── html
│ ├── index.html
│ └── index.php
├── mysql
│ ├── mysql
└── nginx
├── conf.d
└── default.conf
本文转载自机器学习小弟,本文观点不代表123ppp资源网立场,版权归原作者所有,欢迎分享本文,转载请保留出处!