我有一个Laravel项目,我创建了一个docker-compose和dockerfile。
我做docker-compose build,我的问题是:
docker-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"]
可以是权限吗?
第21/30步:COPY --chown = root:www-data ./.env.${environment:-local} /var/www/html/app/.env ---> 7d1038fe2615
步骤26/30:运行composer安装--->在8e3265277308中运行
卸下中间容器8e3265277308 ---> 429553e893a4步骤 27/30:
运行chmod -R g + w / var / www / html / app / vendor->运行 9e276059478b卸下中间容器9e276059478b ---> d52ee5ad4ec4
答案 0 :(得分:1)
构建映像时,将整个当前目录COPY
/var/www/html/app
,然后在那里的内容发生了变化。在docker-compose up
上,您再次将整个文件夹 挂载在此目的地,该文件夹将覆盖docker-compose build
上发生的所有事情。为避免这种情况,只需从volumes
中删除docker-compose.yml
部分。