Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

hnbach's avatar

Shared /vendor between host machine and Docker container

Hi guys, I'm running a Laravel using Docker using the following docker-compose.yml:

version: "3.7"
services:
    cms:
        build: .
        container_name: cms
        volumes:
            - .:/data/cms:delegated
		...
    composer:
        build: .
        container_name: composer
        command: composer install
        volumes:
            - .:/data/cms
		...

My issue:

  • My cms container had the php mongo extension.
  • My host machine installed php without the php mongo extension (not all my projects were dockerized so my host machine installed php as well)

If I logged get_loaded_extensions() in /vendor, it shown the list extensions of host machine (no 'mongodb') => So my vendor's class \MongoDB\Client kept throwing error Class \MongoDB\Driver\Manager was not found.

If I logged get_loaded_extensions() in /app, it shown the list extensions of cms container (have 'mongodb')

=> And if I deployed the app to my prod server (no php installed), both /vendor and /app loaded php extensions from the cms container correctly.

My current assumption:

So I'm currently assuming that there is a confliction between php runtimes of host and cms container in /vendor's codes if I used a separate container for composer installation. More specifically, it prioritizes taking the php runtime of host machine, if it doesn't exist, it will take the container's.

I was also confused due to the fact that while the error of missing mongodb extension was thrown, my app can still connect to mongo db successfully. This made my assumption to be uncertain, because if vendor take host machine's php runtime, my app which called vendor code should be affected as well.

=> Can someone help me to clarify my case?

0 likes
1 reply

Please or to participate in this conversation.