下边来弄弄 docker compose。 的确很好用。
准备
先准备一下文件。
.
├── docker-compose.yml
└── vini123
├── nginx
│ └── default.conf
└── www
└── nginx
└── index.php
这里先看看 docker-compose.yml
文件。
version: '3'
services:
nginx:
image: nginx:1.25.3
container_name: vini123-nginx
restart: always
privileged: true
ports:
- 80:80
- 443:443
environment:
TZ: Asia/Shanghai
volumes:
- ./vini123/nginx/conf.d:/etc/nginx/conf.d
- ./vini123/nginx/etc/cert:/etc/nginx/cert
- ./vini123/nginx/logs:/var/log/nginx
- ./vini123/www:/var/www
depends_on:
- php-fpm
php-fpm:
image: php:8.2-fpm
container_name: vini123-php-fpm
restart: always
privileged: true
environment:
TZ: Asia/Shanghai
volumes:
- ./vini123/www:/var/www
- ./vini123/www/logs:/var/log/php
command: bash -c "pecl install redis && docker-php-ext-enable redis && php-fpm"
links:
- mysql
mysql:
image: mysql:8.2
container_name: vini123-mysql
command:
--character-set-server=utf8mb4
--collation-server=utf8mb4_unicode_ci
--lower_case_table_names=1
restart: always
privileged: true
environment:
TZ: Asia/Shanghai
MYSQL_DATABASE: vini123
MYSQL_USER: vini123
MYSQL_PASSWORD: vini2023
MYSQL_ROOT_PASSWORD: viniroot
volumes:
- ./vini123/mysql-data:/var/lib/mysql
ports:
- '3306:3306'
redis:
image: redis:7.2
container_name: vini123-redis
restart: always
privileged: true
environment:
TZ: Asia/Shanghai
ports:
- "6379:6379"
volumes:
- ./vini123/redis/redis.conf:/etc/redis/redis.conf
- ./vini123/redis/data:/data
command: redis-server /etc/redis/redis.conf
composer:
image: composer:2.6.5
container_name: vini123-composer
environment:
TZ: Asia/Shanghai
volumes:
- ./vini123/utils/composer:/var/www/html
command: install
再看 default.conf
文件。
server {
listen 80;
server_name localhost;
root /var/www/html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass php-fpm:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
最后看 index.php
<?php
phpinfo();
启动
准备上边这么多就够了,开始启动看看吧。
docker-compose up -d
然后来访问 http://localhost
看看。
mysql
redis
到此,一个简单的环境就好了。
下一步
配置 ssh,添加更多的项目。
参考
https://zhuanlan.zhihu.com/p/631317018