您好,登錄后才能下訂單哦!
這篇文章主要講解了“Docker如何部署Laravel應用”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“Docker如何部署Laravel應用”吧!
一、 準備我們的 laravel 應用
# 運行 mix 命令,打包 js、css、img 文件,如果沒有用到 mix 這一步可以省略 npm install npm run production # 安裝 composer.lock 中的依賴 composer install --ignore-platform-reqs --optimize-autoloader --no-dev
二、 準備 apache 配置文件 docker/000-default.conf
<virtualhost *:80> # 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 </virtualhost>
三、 準備 dockerfile 文件
from php:7.3-apache label maintainer="liuzhaowei55@gmail.com" # 設置時區 arg tz=asia/shanghai env tz ${tz} run ln -snf /usr/share/zoneinfo/$tz /etc/localtime && echo $tz > /etc/timezone # 安裝軟件 cron run 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 \ bcmath env pecl_extension \ redis run docker-php-ext-install $php_extension \ && pecl install $pecl_extension \ && docker-php-ext-enable $pecl_extension \ opcache \ && a2enmod rewrite # 訪問端口 expose 80 arg app_env=development env app_env ${app_env} copy --chown=www-data:www-data . /var/www/html copy docker/000-default.conf /etc/apache2/sites-available/000-default.conf workdir /var/www/html
四、準備 dockerignore 文件:.dockerignore(非必需)
/node_modules /.dockerignore /dockerfile
五、準備鏡像入口文件:docker-entrypoint.sh(非必需)
注意一下,此文件需要執行權限,不過此入口文件不是必須的,只是為了在應用運行前執行一些緩存命令,具體可以了解一下。
#!/usr/bin/env bash php artisan cache:clear php artisan config:cache php artisan route:cache php artisan view:cache apache2-foreground
六、運行鏡像
docker run -p 80:80 .
感謝各位的閱讀,以上就是“Docker如何部署Laravel應用”的內容了,經過本文的學習后,相信大家對Docker如何部署Laravel應用這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關知識點的文章,歡迎關注!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。