dockerfile配置lnmp
时间: 2023-10-24 07:04:26 浏览: 301
你可以使用以下的 Dockerfile 配置来搭建 LNMP(Linux + Nginx + MySQL + PHP)环境:
```dockerfile
# 使用官方的 PHP 7.4 镜像作为基础镜像
FROM php:7.4-fpm
# 更新源并安装依赖包
RUN apt-get update && \
apt-get install -y nginx mysql-server supervisor && \
rm -rf /var/lib/apt/lists/*
# 将 Nginx 默认配置文件替换为自定义配置
COPY nginx/default.conf /etc/nginx/sites-available/default
# 将 PHP 配置文件替换为自定义配置
COPY php/php.ini /usr/local/etc/php/conf.d/custom.ini
# 将 Supervisor 配置文件替换为自定义配置
COPY supervisor/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
# 将 PHP 代码复制到容器内的工作目录
COPY src/ /var/www/html/
# 设置工作目录
WORKDIR /var/www/html/
# 暴露 Nginx 默认端口
EXPOSE 80
# 启动 Supervisor 以同时运行 Nginx 和 PHP-FPM
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
```
上述 Dockerfile 的构建过程如下:
1. 使用官方的 PHP 7.4 镜像作为基础镜像。
2. 更新源并安装所需的软件包,包括 Nginx、MySQL 和 Supervisor。
3. 替换默认的 Nginx 配置文件为自定义配置。
4. 替换默认的 PHP 配置文件为自定义配置。
5. 替换默认的 Supervisor 配置文件为自定义配置。
6. 将你的 PHP 代码复制到容器内的工作目录。
7. 设置工作目录为 `/var/www/html/`。
8. 暴露 Nginx 默认的 HTTP 端口(80)。
9. 使用 Supervisor 启动 Nginx 和 PHP-FPM。
你需要将自定义的 Nginx、PHP 和 Supervisor 配置文件放在与 Dockerfile 同一目录下的 `nginx`、`php` 和 `supervisor` 子目录中,并将你的 PHP 代码放在 `src` 子目录中。
阅读全文
相关推荐















