Docker 배치 Laravel 응용-기초 응용

3986 단어 dockerlaravelphp
버 전 설명
  • 본 논문 의 PHP 기초 미 러 사용:php:7.3-apache
  • 본 논문 의 Laravel 버 전 은 다음 과 같다.laravel:5.8.*
  • 1.우리 Laravel 애플 리 케 이 션 준비
    #    mix   ,   js、css、img   ,       mix        
    npm install
    npm run production
    #    composer.lock     
    composer install --ignore-platform-reqs --optimize-autoloader --no-dev

    2.아파 치 설정 파일 준비 하기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.Dockerfile 파일 준비
    FROM php:7.3-apache
    
    LABEL maintainer="[email protected]"
    
    #     
    ARG TZ=Asia/Shanghai
    ENV TZ ${TZ}
    RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
    
    #      
    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
    
    #      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
    

    4.Dockerignore 파일 준비:.dockerignore(필요 하지 않 음)
    /node_modules
    /.dockerignore
    /Dockerfile

    5.미 러 입구 파일 준비: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
    

    6.미 러 실행
    docker run -p 80:80 .

    관련 읽 기
  • Docker 배치 Laravel 응용-기초 응용
  • Docker 배치 Laravel 응용-대기 열&작업 스케줄 링
  • Docker 배치 Laravel 응용 프로그램-사용wkhtmltopdf내 보 내기 PDF
  • 예시 코드
  • 좋은 웹페이지 즐겨찾기