Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Implementation example of Docker deploying Laravel application

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

This article PHP base mirror uses: php:7.3-apache This article Laravel version is: laravel:5.8.* Queue and Task Scheduling We write in the next article

I. Prepare our Laravel application

#Run mix command, package js, css, img files. If mix is not used, you can omit npm installnpm run production#Install the dependencies in composer.lock composer install --ignore-platform-reqs --optimize-autoloader -no-dev

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

III. Prepare Dockerfile

FROM php:7.3-apacheLABEL maintainer="liuzhaowei55@gmail.com"#Set time zone ARG TZ=Asia/ShanghaiENV TZ ${TZ}RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime & echo $TZ > /etc/timezone#Install software cronRUN set -eux \ && apt-get update \ && apt-get install -y --no-install-recommends cron \ && apt-get autoremove \ && apt-get autoclean\ && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* #install extension 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 #access port 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

4. Prepare Dockerignore file: .dockerignore (optional)

/node_modules/.dockerignore/Dockerfile

V. Prepare the mirror entry file: docker-entrypoint.sh (optional)

Note that this file requires execution permissions, but this entry file is not necessary, just to execute some cache commands before the application runs, you can click here to find out about the documentation.

#!/ usr/bin/env bashphp artisan cache:clearphp artisan config:cachephp artisan route:cachephp artisan view:cacheapache2-foreground

VI. Running Mirror Image

docker run -p 80:80 .

The above is all the content of this article, I hope to help everyone's study, but also hope that everyone a lot of support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report