Running composer install within a Dockerfile

后端 未结 4 766
甜味超标
甜味超标 2020-12-23 11:58

I\'m trying to Dockerize my laravel app. The app is already built and in git, but I .gitignore my vendor folder. I\'ve added a Dockerfile, which looks like this:

<         


        
4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-23 12:41

    You can also use the official dockerhub composer image.

    This is an example of a multi-stage build with composer running first in a separate container. The resulting /app/vendor is copied to wherever you want in your final image.

    FROM composer as builder
    WORKDIR /app/
    COPY composer.* ./
    RUN composer install
    ...
    FROM php:7.1-fpm-alpine
    ...
    COPY --from=builder /app/vendor /var/www/vendor
    

提交回复
热议问题