Рубрики
Uncategorized

Развертывание докера Приложение Laravel – базовое приложение

Автор оригинала: David Wong.

Версии.

  • В этой статье ИСПОЛЬЗУЕТСЯ базовое зеркало PHP: php :7.3-apache
  • Версия этой статьи для Laravel выглядит следующим образом: laravel :5.8.*

1. Подготовьте свое приложение Laravel

# run the mix command to package js, CSS, img files, and omit this step if you don't use mix
npm install
npm run production
Install the dependencies in 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 [email protected]
    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

3. Подготовьте Докер-файл

FROM php:7.3-apache

LABEL maintainer="[email protected]"

# set time zone
ARG TZ=Asia/Shanghai
ENV TZ ${TZ}
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

Set up the software source
ARG DEBIAN_URL=mirrors.ustc.edu.cn
ENV DEBIAN_URL ${DEBIAN_URL}
RUN sed -i "s/deb.debian.org/$DEBIAN_URL/g" /etc/apt/sources.list

ARG DEBIAN_SECURITY_URL=mirrors.ustc.edu.cn/debian-security
ENV DEBIAN_SECURITY_URL ${DEBIAN_SECURITY_URL}
RUN sed -i "s|security.debian.org/debian-security|$DEBIAN_SECURITY_URL|g" /etc/apt/sources.list

Install software 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/*
        
# installation extension
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
    
# access port
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

Iv. Подготовьте файл Dockerignore:.dockerignore(необязательно)

/node_modules
/.dockerignore
/Dockerfile

5. Подготовьте зеркальную запись file: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 – планирование очередей и задач
  • Развертывание докера Приложение Laravel – использование wkhtmltopdf Экспорт PDF
  • Пример кода