怎么使用Docker部署Laravel应用-成都快上网建站

怎么使用Docker部署Laravel应用

本文小编为大家详细介绍“怎么使用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


 # 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-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应用
转载源于:http://kswjz.com/article/gcijie.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流