Running composer install within a Dockerfile

0 votes

I'm attempting to Dockerize a Laravel application. The app is already created and in git, but my vendor folder is.gitignored. I've added a Dockerfile with the following contents:

FROM php:7.1-fpm-alpine

RUN apk update && apk add curl && \
  curl -sS | php \
  && chmod +x composer.phar && mv composer.phar /usr/local/bin/composer

RUN apk --no-cache add --virtual .build-deps $PHPIZE_DEPS \
  && apk --no-cache add --virtual .ext-deps libmcrypt-dev freetype-dev \
  libjpeg-turbo-dev libpng-dev libxml2-dev msmtp bash openssl-dev pkgconfig \
  && docker-php-source extract \
  && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ \
                                   --with-png-dir=/usr/include/ \
                                   --with-jpeg-dir=/usr/include/ \
  && docker-php-ext-install gd mcrypt mysqli pdo pdo_mysql zip opcache \
  && pecl install mongodb redis xdebug \
  && docker-php-ext-enable mongodb \
  && docker-php-ext-enable redis \
  && docker-php-ext-enable xdebug \
  && docker-php-source delete \
  && apk del .build-deps

WORKDIR /var/www/html

COPY composer.json composer.lock ./
RUN composer install --no-scripts --no-autoloader

COPY . .
RUN chmod +x artisan

RUN composer dump-autoload --optimize && composer run-script post-install-cmd

CMD php artisan serve --host --port 5001

This appears to function well when I'm building. In the output, I see the dependencies being downloaded and the autoload file being generated. However, once the build is finished, the vendor folder is missing. I'm presuming everything was done in a temporary container that was subsequently removed? So when I run docker-compose up, I get: Fatal error: require(): Failed opening required '/var/www/html/bootstrap/../vendor/autoload.php'

I looked at some other threads but wasn't able to find a suitable answer.

Apr 12, 2022 in Docker by Abhijeet
• 180 points

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Docker

0 votes
1 answer
+1 vote
1 answer

How do i install jenkins using a dockerfile on a windows container?

Here is to how you can install JENKINS ...READ MORE

answered Aug 22, 2019 in Docker by Sirajul
• 59,230 points
0 votes
0 answers

How to install PHP composer inside a docker container

I'm trying to figure out how to ...READ MORE

Apr 12, 2022 in Docker by Abhijeet
• 180 points
0 votes
1 answer
0 votes
1 answer

Is Dockerfile versioning a best practice?

According to me , it will be ...READ MORE

answered Jun 17, 2018 in Docker by shubham
• 7,340 points
0 votes
1 answer

How to continue running a docker container which is already exited?

Restart an existing container after you exited ...READ MORE

answered Jul 19, 2018 in Docker by Sophie may
• 10,610 points
+2 votes
1 answer
+2 votes
1 answer

Deploy Docker Containers from Docker Cloud

To solve this problem, I followed advice ...READ MORE

answered Sep 3, 2018 in AWS by Priyaj
• 58,090 points
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP