Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vendor folder is not present in my docker image

Tags:

docker

laravel

I'm trying to build a deployable image of my laravel app into docker.

Here is my dockerfile:

FROM php:7.1.14-fpm
ENV node_version 8.4.0
ENV npm_version 5.7.1

RUN echo "deb http://ftp.de.debian.org/debian stretch main " >> /etc/apt/sources.list \
&& apt-get update -y && apt-get install -y openssl zip unzip git automake \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        libmcrypt-dev \
        libpng-dev \
        libmagickwand-dev vim --no-install-recommends \
&& apt-get remove -y libgnutls-deb0-28 \
&& apt-get purge --auto-remove -y g++ \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install pdo pdo_mysql mbstring zip -j$(nproc) iconv mcrypt -j$(nproc) gd

WORKDIR /app
COPY . /app
COPY ./entrypoint.sh /tmp

RUN touch ./resources/assets/less/_main_full/main.less \
&& mv ./.env.local ./.env \
&& mv ./.dockerignore-local ./.dockerignore

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \
&& composer install --no-interaction

RUN  curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash \
&& export NVM_DIR="$HOME/.nvm" \
&& [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" \
&& nvm install ${node_version} \
&& npm install -g npm@${npm_version} \
&& npm install \
&& npm run dev

RUN chown -R www-data:www-data \
        /app/storage \
        /app/bootstrap/cache \
&& chmod 755 /tmp/entrypoint.sh

CMD ["/tmp/entrypoint.sh"]

In the build logs, I can see composer is invoked and working well.

 ---> Running in c4eb03cbb690
All settings correct for using Composer
Downloading...

Composer (version 1.6.3) successfully installed to: /usr/local/bin/composer
Use it: php /usr/local/bin/composer

Do not run Composer as root/super user! See https://getcomposer.org/root for details
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Package operations: 121 installs, 0 updates, 0 removals
  - Installing symfony/finder (v3.4.4): Downloading (100%)         
  - Installing symfony/polyfill-mbstring (v1.7.0): Downloading (100%)         
  - Installing symfony/var-dumper (v3.4.4): Downloading (100%)         
  - Installing psr/log (1.0.2): Downloading (100%)         
  - Installing maximebf/debugbar (1.13.1): Downloading (100%)         
  - Installing vlucas/phpdotenv (v2.4.0): Downloading (100%)         
  - Installing symfony/css-selector (v3.1.10): Downloading (100%)         
  - Installing tijsverkoyen/css-to-inline-styles (2.2.1): Downloading (100%)         
  - Installing symfony/routing (v3.4.4): Downloading (100%)         
  - Installing symfony/process (v3.4.4): Downloading (100%)         
  - Installing paragonie/random_compat (v2.0.11): Downloading (100%)         
  - Installing symfony/polyfill-php70 (v1.7.0): Downloading (100%)         
  - Installing symfony/http-foundation (v3.4.4): Downloading (100%)         
  - Installing symfony/event-dispatcher (v4.0.4): Downloading (100%)         
  - Installing symfony/debug (v3.4.4): Downloading (100%)         
  - Installing symfony/http-kernel (v3.4.4): Downloading (100%)         
  - Installing symfony/console (v3.4.4): Downloading (100%)         
  - Installing doctrine/lexer (v1.0.1): Downloading (100%)         
  - Installing egulias/email-validator (2.1.3): Downloading (100%)         
  - Installing swiftmailer/swiftmailer (v6.0.2): Downloading (100%)         
  - Installing ramsey/uuid (3.7.3): Downloading (100%)         
  - Installing psr/simple-cache (1.0.0): Downloading (100%)         
  - Installing psr/container (1.0.0): Downloading (100%)         
  - Installing symfony/translation (v3.4.4): Downloading (100%)         
  - Installing nesbot/carbon (1.22.1): Downloading (100%)         
  - Installing mtdowling/cron-expression (v1.2.1): Downloading (100%)         
  - Installing monolog/monolog (1.23.0): Downloading (100%)         
  - Installing league/flysystem (1.0.42): Downloading (100%)         
  - Installing erusev/parsedown (1.6.4): Downloading (100%)         
  - Installing doctrine/inflector (v1.3.0): Downloading (100%)         
  - Installing laravel/framework (v5.5.33): Downloading (100%)         
  - Installing barryvdh/laravel-debugbar (v2.4.3): Downloading (100%)         
  - Installing symfony/class-loader (v3.4.4): Downloading (100%)         
  - Installing barryvdh/reflection-docblock (v2.0.4): Downloading (100%)         
  - Installing barryvdh/laravel-ide-helper (v2.4.1): Downloading (100%)         
  - Installing knplabs/knp-snappy (v1.0.4): Downloading (100%)         
  - Installing barryvdh/laravel-snappy (v0.4.0): Downloading (100%)         
  - Installing cocur/slugify (v2.5): Downloading (100%)         
  - Installing cviebrock/eloquent-sluggable (4.2.4): Downloading (100%)         
  - Installing davejamesmiller/laravel-breadcrumbs (3.0.3): Downloading (100%)         
  - Installing doctrine/annotations (v1.6.0): Downloading (100%)         
  - Installing doctrine/cache (v1.7.1): Downloading (100%)         
  - Installing doctrine/collections (v1.5.0): Downloading (100%)         
  - Installing doctrine/common (v2.7.3): Downloading (100%)         
  - Installing doctrine/dbal (v2.5.13): Downloading (100%)         
  - Installing fzaninotto/faker (v1.7.1): Downloading (100%)         
  - Installing guzzlehttp/promises (v1.3.1): Downloading (100%)         
  - Installing psr/http-message (1.0.1): Downloading (100%)         
  - Installing guzzlehttp/psr7 (1.4.2): Downloading (100%)         
  - Installing lab404/laravel-impersonate (1.2.2): Downloading (100%)         
  - Installing zendframework/zend-diactoros (1.7.0): Downloading (100%)         
  - Installing symfony/psr-http-message-bridge (v1.0.2): Downloading (100%)         
  - Installing phpseclib/phpseclib (2.0.9): Downloading (100%)         
  - Installing league/event (2.1.2): Downloading (100%)         
  - Installing lcobucci/jwt (3.2.2): Downloading (100%)         
  - Installing defuse/php-encryption (v2.1.0): Downloading (100%)         
  - Installing league/oauth2-server (6.1.1): Downloading (100%)         
  - Installing guzzlehttp/guzzle (6.3.0): Downloading (100%)         
  - Installing firebase/php-jwt (v4.0.0): Downloading (100%)         
  - Installing laravel/passport (v3.0.2): Downloading (100%)         
  - Installing league/oauth1-client (1.7.0): Downloading (100%)         
  - Installing laravel/socialite (v3.0.0): Downloading (100%)         
  - Installing laravelcollective/html (5.5.x-dev 2f6dc39): Downloading (100%)         
  - Installing intervention/image (2.4.1): Downloading (100%)         
  - Installing danielstjules/stringy (2.4.0): Downloading (100%)         
  - Installing laravolt/avatar (1.8.1): Downloading (100%)         
  - Installing mtdowling/jmespath.php (2.4.0): Downloading (100%)         
  - Installing aws/aws-sdk-php (3.52.2): Downloading (100%)         
  - Installing league/flysystem-aws-s3-v3 (1.0.18): Downloading (100%)         
  - Installing liopic/korean-romanizer (1.0): Downloading (100%)         
  - Installing phpoffice/phpexcel (1.8.1): Downloading (100%)         
  - Installing symfony/polyfill-util (v1.7.0): Downloading (100%)         
  - Installing symfony/polyfill-php56 (v1.7.0): Downloading (100%)         
  - Installing nikic/php-parser (v3.1.4): Downloading (100%)         
  - Installing jeremeamia/superclosure (2.3.0): Downloading (100%)         
  - Installing maatwebsite/excel (2.1.24): Downloading (100%)         
  - Installing owen-it/laravel-auditing (2.3.7): Downloading (100%)         
  - Installing proengsoft/laravel-jsvalidation (v1.6.1): Downloading (100%)         
  - Installing rap2hpoutre/laravel-log-viewer (v0.7.1): Downloading (100%)         
  - Installing sentry/sentry (1.8.2): Downloading (100%)         
  - Installing sentry/sentry-laravel (0.3.0): Downloading (100%)         
  - Installing spatie/db-dumper (1.5.1): Downloading (100%)         
  - Installing spatie/laravel-backup (3.10.1): Downloading (100%)         
  - Installing thomaswelton/gravatarlib (0.1.0): Downloading (100%)         
  - Installing thomaswelton/laravel-gravatar (1.1.3): Downloading (100%)         
  - Installing torann/geoip (1.0.5): Downloading (100%)         
  - Installing webpatser/laravel-countries (dev-master 2568394): Downloading (100%)         
  - Installing kalnoy/nestedset (v4.3.1): Downloading (100%)         
  - Installing xoco70/laravel-tournaments (dev-master 8c9eac5): Downloading (100%)         
  - Installing symfony/dom-crawler (v3.1.10): Downloading (100%)         
  - Installing sebastian/version (2.0.1): Downloading (100%)         
  - Installing sebastian/resource-operations (1.0.0): Downloading (100%)         
  - Installing sebastian/recursion-context (3.0.0): Downloading (100%)         
  - Installing sebastian/object-reflector (1.1.1): Downloading (100%)         
  - Installing sebastian/object-enumerator (3.0.3): Downloading (100%)         
  - Installing sebastian/global-state (2.0.0): Downloading (100%)         
  - Installing sebastian/exporter (3.1.0): Downloading (100%)         
  - Installing sebastian/environment (3.1.0): Downloading (100%)         
  - Installing sebastian/diff (2.0.1): Downloading (100%)         
  - Installing sebastian/comparator (2.1.3): Downloading (100%)         
  - Installing phpunit/php-text-template (1.2.1): Downloading (100%)         
  - Installing doctrine/instantiator (1.1.0): Downloading (100%)         
  - Installing phpunit/phpunit-mock-objects (5.0.6): Downloading (100%)         
  - Installing phpunit/php-timer (1.0.9): Downloading (100%)         
  - Installing phpunit/php-file-iterator (1.4.5): Downloading (100%)         
  - Installing theseer/tokenizer (1.1.0): Downloading (100%)         
  - Installing sebastian/code-unit-reverse-lookup (1.0.1): Downloading (100%)         
  - Installing phpunit/php-token-stream (2.0.2): Downloading (100%)         
  - Installing phpunit/php-code-coverage (5.3.0): Downloading (100%)         
  - Installing webmozart/assert (1.3.0): Downloading (100%)         
  - Installing phpdocumentor/reflection-common (1.0.1): Downloading (100%)         
  - Installing phpdocumentor/type-resolver (0.4.0): Downloading (100%)         
  - Installing phpdocumentor/reflection-docblock (4.3.0): Downloading (100%)         
  - Installing phpspec/prophecy (1.7.3): Downloading (100%)         
  - Installing phar-io/version (1.0.1): Downloading (100%)         
  - Installing phar-io/manifest (1.0.1): Downloading (100%)         
  - Installing myclabs/deep-copy (1.7.0): Downloading (100%)         
  - Installing phpunit/phpunit (6.5.6): Downloading (100%)         
  - Installing laravel/browser-kit-testing (v2.0.1): Downloading (100%)         
  - Installing hamcrest/hamcrest-php (v1.2.2): Downloading (100%)         
  - Installing mockery/mockery (0.9.9): Downloading (100%)         
symfony/var-dumper suggests installing ext-intl (To show region name in time zone dump)
symfony/var-dumper suggests installing ext-symfony_debug ()
maximebf/debugbar suggests installing kriswallsmith/assetic (The best way to manage assets)
maximebf/debugbar suggests installing predis/predis (Redis storage)
symfony/routing suggests installing symfony/config (For using the all-in-one router or any loader)
symfony/routing suggests installing symfony/dependency-injection (For loading routes from a service)
symfony/routing suggests installing symfony/expression-language (For using expression matching)
symfony/routing suggests installing symfony/yaml (For using the YAML loader)
paragonie/random_compat suggests installing ext-libsodium (Provides a modern crypto API that can be used to generate random bytes.)
symfony/event-dispatcher suggests installing symfony/dependency-injection ()
symfony/http-kernel suggests installing symfony/browser-kit ()
symfony/http-kernel suggests installing symfony/config ()
symfony/http-kernel suggests installing symfony/dependency-injection ()
symfony/console suggests installing symfony/lock ()
egulias/email-validator suggests installing ext-intl (PHP Internationalization Libraries are required to use the SpoofChecking validation)
ramsey/uuid suggests installing ext-libsodium (Provides the PECL libsodium extension for use with the SodiumRandomGenerator)
ramsey/uuid suggests installing ext-uuid (Provides the PECL UUID extension for use with the PeclUuidTimeGenerator and PeclUuidRandomGenerator)
ramsey/uuid suggests installing ircmaxell/random-lib (Provides RandomLib for use with the RandomLibAdapter)
ramsey/uuid suggests installing moontoast/math (Provides support for converting UUID to 128-bit integer (in string form).)
ramsey/uuid suggests installing ramsey/uuid-console (A console application for generating UUIDs with ramsey/uuid)
ramsey/uuid suggests installing ramsey/uuid-doctrine (Allows the use of Ramsey\Uuid\Uuid as Doctrine field type.)
symfony/translation suggests installing symfony/config ()
symfony/translation suggests installing symfony/yaml ()
monolog/monolog suggests installing doctrine/couchdb (Allow sending log messages to a CouchDB server)
monolog/monolog suggests installing ext-amqp (Allow sending log messages to an AMQP server (1.0+ required))
monolog/monolog suggests installing ext-mongo (Allow sending log messages to a MongoDB server)
monolog/monolog suggests installing graylog2/gelf-php (Allow sending log messages to a GrayLog2 server)
monolog/monolog suggests installing mongodb/mongodb (Allow sending log messages to a MongoDB server via PHP Driver)
monolog/monolog suggests installing php-amqplib/php-amqplib (Allow sending log messages to an AMQP server using php-amqplib)
monolog/monolog suggests installing php-console/php-console (Allow sending log messages to Google Chrome)
monolog/monolog suggests installing rollbar/rollbar (Allow sending log messages to Rollbar)
monolog/monolog suggests installing ruflin/elastica (Allow sending log messages to an Elastic Search server)
league/flysystem suggests installing league/flysystem-aws-s3-v2 (Allows you to use S3 storage with AWS SDK v2)
league/flysystem suggests installing league/flysystem-azure (Allows you to use Windows Azure Blob storage)
league/flysystem suggests installing league/flysystem-cached-adapter (Flysystem adapter decorator for metadata caching)
league/flysystem suggests installing league/flysystem-eventable-filesystem (Allows you to use EventableFilesystem)
league/flysystem suggests installing league/flysystem-rackspace (Allows you to use Rackspace Cloud Files)
league/flysystem suggests installing league/flysystem-sftp (Allows you to use SFTP server storage via phpseclib)
league/flysystem suggests installing league/flysystem-webdav (Allows you to use WebDAV storage)
league/flysystem suggests installing league/flysystem-ziparchive (Allows you to use ZipArchive adapter)
league/flysystem suggests installing spatie/flysystem-dropbox (Allows you to use Dropbox storage)
league/flysystem suggests installing srmklive/flysystem-dropbox-v2 (Allows you to use Dropbox storage for PHP 5 applications)
laravel/framework suggests installing ext-pcntl (Required to use all features of the queue worker.)
laravel/framework suggests installing laravel/tinker (Required to use the tinker console command (~1.0).)
laravel/framework suggests installing league/flysystem-cached-adapter (Required to use Flysystem caching (~1.0).)
laravel/framework suggests installing league/flysystem-rackspace (Required to use the Flysystem Rackspace driver (~1.0).)
laravel/framework suggests installing nexmo/client (Required to use the Nexmo transport (~1.0).)
laravel/framework suggests installing pda/pheanstalk (Required to use the beanstalk queue driver (~3.0).)
laravel/framework suggests installing predis/predis (Required to use the redis cache and queue drivers (~1.0).)
laravel/framework suggests installing pusher/pusher-php-server (Required to use the Pusher broadcast driver (~3.0).)
symfony/class-loader suggests installing symfony/polyfill-apcu (For using ApcClassLoader on HHVM)
barryvdh/reflection-docblock suggests installing dflydev/markdown (~1.0)
knplabs/knp-snappy suggests installing h4cc/wkhtmltoimage-amd64 (Provides wkhtmltoimage-amd64 binary for Linux-compatible machines, use version `~0.12` as dependency)
knplabs/knp-snappy suggests installing h4cc/wkhtmltoimage-i386 (Provides wkhtmltoimage-i386 binary for Linux-compatible machines, use version `~0.12` as dependency)
knplabs/knp-snappy suggests installing h4cc/wkhtmltopdf-amd64 (Provides wkhtmltopdf-amd64 binary for Linux-compatible machines, use version `~0.12` as dependency)
knplabs/knp-snappy suggests installing h4cc/wkhtmltopdf-i386 (Provides wkhtmltopdf-i386 binary for Linux-compatible machines, use version `~0.12` as dependency)
knplabs/knp-snappy suggests installing wemersonjanuario/wkhtmltopdf-windows (Provides wkhtmltopdf executable for Windows, use version `~0.12` as dependency)
doctrine/cache suggests installing alcaeus/mongo-php-adapter (Required to use legacy MongoDB driver)
phpseclib/phpseclib suggests installing ext-gmp (Install the GMP (GNU Multiple Precision) extension in order to speed up arbitrary precision integer arithmetic operations.)
phpseclib/phpseclib suggests installing ext-libsodium (SSH2/SFTP can make use of some algorithms provided by the libsodium-php extension.)
lcobucci/jwt suggests installing mdanter/ecc (Required to use Elliptic Curves based algorithms.)
intervention/image suggests installing ext-imagick (to use Imagick based image processing.)
intervention/image suggests installing intervention/imagecache (Caching extension for the Intervention Image library)
aws/aws-sdk-php suggests installing aws/aws-php-sns-message-validator (To validate incoming SNS notifications)
spatie/laravel-backup suggests installing irazasyed/telegram-bot-sdk (Allows notifications to be sent using Telegram Bot)
spatie/laravel-backup suggests installing maknz/slack (Allows notifications to be sent via Slack)
thomaswelton/gravatarlib suggests installing twig/twig (>=1.4.0)
torann/geoip suggests installing geoip2/geoip2 (Required to use the MaxMind database or web service with GeoIP (~2.1).)
sebastian/global-state suggests installing ext-uopz (*)
phpunit/phpunit-mock-objects suggests installing ext-soap (*)
phpunit/php-code-coverage suggests installing ext-xdebug (^2.5.5)
phpunit/phpunit suggests installing ext-xdebug (*)
phpunit/phpunit suggests installing phpunit/php-invoker (^1.1)
Package phpoffice/phpexcel is abandoned, you should avoid using it. Use phpoffice/phpspreadsheet instead.
Generating autoload files
> Illuminate\Foundation\ComposerScripts::postInstall
> php artisan optimize
Removing intermediate container c4eb03cbb690

But when I run docker compose, and connect to my container, I can see there is no vendor/ folder, I have to execute again composer install that load dependencies from cache.

It is to be mentionned that I also have a .dockerignore that has inside vendor/ directory, but as I understand it, .dockerignore should have an effect on the COPY instruction but then, if it is built inside dockerfile, vendor folder should exist...

Why am I wrong ???

like image 613
Juliatzin Avatar asked Mar 23 '18 10:03

Juliatzin


People also ask

What is directory in Dockerfile?

The WORKDIR command is used to define the working directory of a Docker container at any given time. The command is specified in the Dockerfile. Any RUN , CMD , ADD , COPY , or ENTRYPOINT command will be executed in the specified working directory.

Does Workdir Create directory docker?

WORKDIR. The WORKDIR instruction sets a working directory for other Dockerfile instructions, such as RUN , CMD , and also the working directory for running instances of the container image.


2 Answers

Could you share your docker-compose.yml file?

It is very possible that you are creating a shared volume between your host machine and container using docker-compose. Something that looks like this:

services:
  app:
    build:
      context: .
      dockerfile: <path-to-your-Dockerfile>
    volumes:
      - <your-project-path>:/app

Volumes are created after you have built your image and live outside your image/container.

What this means is that the volume you create can potentially overwrite whatever files you have created or installed when building your image.

like image 133
Nizar El Berjawi Avatar answered Oct 08 '22 14:10

Nizar El Berjawi


.dockerignore is solely for loading the build context, and is not applicable when talking about artifacts that are created by the build process. You can and should keep /vendor in your .dockerignore file if you are recreating that folder/running composer each time you build. It is not necessary for Docker to have access to the contents of this folder in order to build your container and including them will just slow down the build.

The reason that you aren't seeing the /vendor folder after the build is finished is this: You are generating the /vendor folder when you do the composer install --no-interaction step which occurs in an intermediate layer (not the final layer). A build step that happens after this is overwriting the folder along with the artifacts that were generated. This can happen even if the composer step is the last item in your Dockerfile if as @nizar-el-berjawi suggests, you are mounting your source folder as a volume in your docker-compose.yml (presumably so you can develop in the container and update source as you go on the host), Docker will run a final mount step that will generate a layer on top of what you have in your Dockerfile. When Docker mounts the source directory, it overwrites the copy that it made during the build with the host source directory that is missing the /vendor sub-directory. Poof!

So to ensure that the /vendor folder is kept in the container, there are several options:

  • Move the composer install step in your Dockerfile into the final CMD command that specifies what to do when the container loads (and happens after volumes are mapped). Something like:

    CMD composer install --no-interaction 
        &&\ ["/tmp/entrypoint.sh"]
    

    Note that in this scenario, the container build will finish before composer install is complete/done, so if you use docker-compose build up [...etc] to build then your app will not be done building and will not be available until the composer step is complete. You can manually track the composer progress using docker logs on the host machine:

    docker logs --follow [image_name/container_id]
    

    To exit the log watcher press the Q key

    If you require knowledge of completeness (e.g. for automated testing) this method isn't recommended (use one of the below methods instead)

  • Don't map your host source volume to the application directory. This will stop Docker from overwriting the folder but changes you make in the container will not propagate to the host. This is fine for a production build. On dev builds where you need to propagate code changes in the container back to the host or vice versa for testing, you can map the folder (use a separate docker-compose.yml file for these build targets). You'll have to run the composer install command manually in the container or on the host using docker exec after the build finishes:

    docker exec -it [image_name/container_id] composer install --no-interaction
    
  • Move the /vendor folder after the composer step to a location that isn't being used for a volume in docker-compose.yml (e.g. /tmp/vendor ) and copy it back in the CMD section of your Dockerfile so that it is restored from the build whenever the container is (re)started.

    RUN mv vendor /tmp/vendor
    CMD cp -a /tmp/vendor vendor && ["/tmp/entrypoint.sh"]
    
like image 2
Peter Kionga-Kamau Avatar answered Oct 08 '22 15:10

Peter Kionga-Kamau