Dockerfile不会在Laravel中创建文件和文件夹

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (1)
  • 关注 (0)
  • 查看 (239)

我有一个Laravel项目,我创建了一个docker-compose和dockerfile。

我做docker-compose构建,我的问题是:

  1. 它不会创建文件夹供应商(composer install)。
  2. 不要将.env.local复制到.env
  3. 不要创建node_modules文件夹

泊坞窗,compose.yml

版本:“3”

services:
  api:
    container_name: nadal_api
    build:
      context: .
      dockerfile: Dockerfile
    volumes:
      - .:/var/www/html/app
    ports:
      - 5002:80

DockerFile

FROM composer:latest AS composer

#Generamos el primer build desde un container de nodejs
FROM node:latest as nodebuild
COPY --chown=root:www-data . /var/www/html/app
WORKDIR /var/www/html/app
RUN npm install
RUN npm run production

#Tomamos la imagen de php fpm para utilizar las librerias compiladas
FROM php:7.2-fpm-stretch

#Instalamos nginx y otras dependencias del framework
RUN apt-get update && apt-get install -y \
    apt-transport-https \
    wget \
    lsb-release \
    libxml2-dev \
    nginx \
    ca-certificates \
    git \
    zip

#Compilamos pgsql
RUN apt-get install -y libpq-dev \
    && docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \
    && docker-php-ext-install pdo pdo_pgsql pgsql

#Compilamos las librerias requeridas por laravel
RUN docker-php-ext-install pdo pdo_mysql
RUN docker-php-ext-install xml
RUN docker-php-ext-install mbstring

#Install supervisor porque debemos tener dos procesos, nginx y fpm
RUN wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
RUN echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/php.list

RUN apt-get update && apt-get install -y \
    supervisor \
    curl \
    libssl-dev \
    libmcrypt-dev

#Copiamos las configuraciones de nginx, el host y supervisor
ADD docker/nginx.conf /etc/nginx/nginx.conf
ADD docker/virtualhost.conf /etc/nginx/conf.d/default.conf
ADD docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf

#Copiamos el projecto con los modulos de node y los assets compilados
COPY --from=nodebuild --chown=root:www-data /var/www/html/app /var/www/html/app
COPY --chown=root:www-data ./.env.local /var/www/html/app/.env

#Aplicamos los permisos que corresponden
RUN chmod -R g+w /var/www/html/app/storage
RUN chmod -R g+w /var/www/html/app/bootstrap

#Copiamos composer
COPY --from=composer /usr/bin/composer /usr/bin/composer

##Download composer packages
WORKDIR /var/www/html/app
RUN composer install
RUN chmod -R g+w /var/www/html/app/vendor
RUN php artisan key:generate

EXPOSE 80

CMD ["/usr/bin/supervisord"]

可以是权限吗?

Step 21/30 : COPY --chown=root:www-data ./.env.${environment:-local} /var/www/html/app/.env ---> 7d1038fe2615

Step 26/30 : RUN composer install ---> Running in 8e3265277308

Removing intermediate container 8e3265277308 ---> 429553e893a4 Step 27/30 :

RUN chmod -R g+w /var/www/html/app/vendor ---> Running in 9e276059478b Removing intermediate container 9e276059478b ---> d52ee5ad4ec4

提问于
用户回答回答于

在构建映像时,COPY将整个当前目录设置为/var/www/html/app,然后在那里发生内容。在docker-compose up,您将整个文件夹再次挂载到此目标,这将覆盖发生的所有内容docker-compose build。为避免这种情况,只需volumes从您的部件中删除该部件docker-compose.yml

扫码关注云+社区

领取腾讯云代金券

年度创作总结 领取年终奖励