gpt4 book ai didi

php - 带有Laravel的Docker

转载 作者:行者123 更新时间:2023-12-02 19:56:30 25 4
gpt4 key购买 nike

我正在使用Docker设置开发环境。我需要

  • NGINX(网络服务)
  • PHP 7.2(应用程序)
  • MARIADB 10.3(数据库)

  • 在应用程序容器中,我必须安装composer,我将使用laravel进行工作。

    RUN composer install中使用 COPY .env.example .envdockerfile安装 vendor并配置 .env,我没有收到任何错误消息,但是也没有创建任何文件。

    docker-compose.yml
    version: '3'
    services:
    app:
    volumes:
    - ./:/var/www
    - ./php/local.ini:/usr/local/etc/php/conf.d/local.ini
    build:
    context: .
    dockerfile: Dockerfile
    image: php:7.2
    container_name: app
    restart: unless-stopped
    tty: true
    working_dir: /var/www
    networks:
    - app-network


    webserver:
    image: nginx:alpine
    container_name: webserver
    restart: unless-stopped
    tty: true
    ports:
    - "80:80"
    - "443:443"
    networks:
    - app-network
    volumes:
    - ./:/var/www
    - ./nginx/conf.d/:/etc/nginx/conf.d/

    db:
    image: mariadb:10.3
    container_name: db
    restart: unless-stopped
    tty: true
    ports:
    - "3306:3306"
    environment:
    MYSQL_DATABASE: db
    MYSQL_ROOT_PASSWORD: pass
    SERVICE_TAGS: dev
    SERVICE_NAME: mysql
    networks:
    - app-network
    volumes:
    - dbdata:/var/lib/mysql

    networks:
    app-network:
    driver: bridge

    volumes:
    dbdata:
    driver: local

    dockerfile
    FROM php:7.2-fpm

    # Copy composer.lock and composer.json
    COPY composer.lock composer.json /var/www/

    # Set working directory
    WORKDIR /var/www

    # Install dependencies
    RUN apt-get update && apt-get install -y \
    build-essential \
    mariadb-client-10.3 \
    libpng-dev \
    libjpeg62-turbo-dev \
    libfreetype6-dev \
    locales \
    zip \
    jpegoptim optipng pngquant gifsicle \
    vim \
    unzip \
    git \
    curl

    # Clear cache
    RUN apt-get clean && rm -rf /var/lib/apt/lists/*

    # Install extensions
    RUN docker-php-ext-install pdo_mysql mbstring zip exif pcntl
    RUN docker-php-ext-configure gd --with-gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include/
    RUN docker-php-ext-install gd

    # Install composer
    RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

    # Add user for laravel application
    RUN groupadd -g 1000 www
    RUN useradd -u 1000 -ms /bin/bash -g www www

    # Copy existing application directory contents
    COPY . /var/www

    # Copy existing application directory permissions
    COPY --chown=www:www . /var/www

    # Run composer install
    RUN composer install

    # Create the .env from the .env.example
    COPY .env.example .env

    # Change current user to www
    USER www

    # Expose port 9000 and start php-fpm server
    EXPOSE 9000
    CMD ["php-fpm"]

    最佳答案

    我创建了一个安装程序,用于在Github上使用NGINX Web服务器和MYSQL数据库来部署Laravel应用程序。
    设置起来应该很容易。如果您遇到任何问题,请随时在Github上提出问题,或在这里问我。

    关于php - 带有Laravel的Docker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57531072/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com