Docker部署Laravel应用的实现示例
发表于:2025-12-02 作者:千家信息网编辑
千家信息网最后更新 2025年12月02日,本文 PHP 基础镜像使用:php:7.3-apache本文 Laravel 版本为:laravel:5.8.*队列和任务调度我们在下一篇写一、 准备我们的 Laravel 应用# 运行 mix 命令
千家信息网最后更新 2025年12月02日Docker部署Laravel应用的实现示例
- 本文 PHP 基础镜像使用:php:7.3-apache
- 本文 Laravel 版本为:laravel:5.8.*
- 队列和任务调度我们在下一篇写
一、 准备我们的 Laravel 应用
# 运行 mix 命令,打包 js、css、img 文件,如果没有用到 mix 这一步可以省略npm installnpm run production# 安装 composer.lock 中的依赖composer install --ignore-platform-reqs --optimize-autoloader --no-dev
二、 准备 Apache 配置文件 docker/000-default.conf
# The ServerName directive sets the request scheme, hostname and port that # the server uses to identify itself. This is used when creating # redirection URLs. In the context of virtual hosts, the ServerName # specifies what hostname must appear in the request's Host: header to # match this virtual host. For the default virtual host (this file) this # value is not decisive as it is used as a last resort host regardless. # However, you must set it for any further virtual host explicitly. #ServerName www.example.com ServerAdmin liuzhaowei55@gmail.com DocumentRoot /var/www/html/public # Available loglevels: trace8, ..., trace1, debug, info, notice, warn, # error, crit, alert, emerg. # It is also possible to configure the loglevel for particular # modules, e.g. #LogLevel info ssl:warn ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined # For most configuration files from conf-available/, which are # enabled or disabled at a global level, it is possible to # include a line for only one particular virtual host. For example the # following line enables the CGI configuration for this host only # after it has been globally disabled with "a2disconf". #Include conf-available/serve-cgi-bin.conf
三、 准备 Dockerfile 文件
FROM php:7.3-apacheLABEL maintainer="liuzhaowei55@gmail.com"# 设置时区ARG TZ=Asia/ShanghaiENV TZ ${TZ}RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone# 安装软件 cronRUN set -eux \ && apt-get update \ && apt-get install -y --no-install-recommends cron \ && apt-get autoremove \ && apt-get autoclean \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* # 安装拓展ENV PHP_EXTENSION \ pdo_mysql \ bcmathENV PECL_EXTENSION \ redisRUN docker-php-ext-install $PHP_EXTENSION \ && pecl install $PECL_EXTENSION \ && docker-php-ext-enable $PECL_EXTENSION \ opcache \ && a2enmod rewrite # 访问端口EXPOSE 80ARG APP_ENV=developmentENV APP_ENV ${APP_ENV}COPY --chown=www-data:www-data . /var/www/htmlCOPY docker/000-default.conf /etc/apache2/sites-available/000-default.confWORKDIR /var/www/html四、准备 Dockerignore 文件:.dockerignore(非必需)
/node_modules/.dockerignore/Dockerfile
五、准备镜像入口文件:docker-entrypoint.sh(非必需)
注意一下,此文件需要执行权限,不过此入口文件不是必须的,只是为了在应用运行前执行一些缓存命令,具体可以点这里去文档了解一下。
#!/usr/bin/env bashphp artisan cache:clearphp artisan config:cachephp artisan route:cachephp artisan view:cacheapache2-foreground
六、运行镜像
docker run -p 80:80 .
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
文件
准备
镜像
运行
应用
入口
命令
任务
内容
只是
基础
就是
文档
时区
权限
版本
端口
缓存
软件
队列
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
数据库与课程对应关系
网络安全涉及内容
专利文摘数据库的网址是
天涯明月刀如何清理数据库
计算机网络技术是不是网络工程
无法修改服务器密码
数据库补码
xeon服务器cpu多少钱
软件开发工具pd
服务器所使用的管理接口
网络安全手抄报没名字
sql数据库如何附加
网络安全与执法专业硕士
一梦江湖服务器安卓端
mysql数据库换机器
服务器运维管理规范
网络技术部总结
科锐网络技术
tl ac200 数据库
贱圣方舟火影服务器全部的人
鲲鹏平台软件开发
复杂排序的数据库
数据库链接如何发送
网络安全 完整性
美国科技互联网公司排行榜
光遇游戏服务器是什么怎么填
中国移动软件开发哪个职位好
数据库update的作用
网络安全保险英语
海普森服务器