i want to run a specific version of phpUnit WITHIN a docker container. This container will use a specific version of php. i.e


Its a lareval application. i have install phpunit via composer on the hostfiles and then used the volume command to transfer this to the container. my composer.json file has following entry:

"require-dev": { "phpunit/phpunit": "^5.0" }

This is my docker run command to run the test on my testdev container:

docker run --rm -it -v ~/Users/mow/Documents/devFolder/testdev:/app testdev_php "php ./vendor/bin/phpunit"

This returns the error:

exec: fatal: unable to exec php ./vendor/bin/phpunit: No such file or directory

i am unclear why it says this because te vendor directory is at the root of my site directory.

this is my dockerfile

FROM php:5.6-apache


RUN apt-get update && apt-get install -y \
    libldap2-dev \
    git \
    --no-install-recommends \
    && rm -r /var/lib/apt/lists/* \
    && docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu/ \
    && docker-php-ext-install ldap \
    && docker-php-ext-install mysqli pdo pdo_mysql

#install xdebug 
RUN git clone https://github.com/xdebug/xdebug.git \
    && cd xdebug \
    && git checkout tags/XDEBUG_2_5_5 \
    && phpize \
    && ./configure --enable-xdebug \
    && make \
    && make install

RUN a2enmod rewrite

COPY ./docker/rootfs /
COPY . /app


ENTRYPOINT ["/init"]

I guess the real question is this: what is the correct way to run a phpUnit test within a docker container so that its subject to the php version within that container.

  • Check your logs, but you're copying data into your container at the point of your mount, that sounds likely to cause problem, a full log with the directory where you're executing the command would help spotting the problem.
    – Tensibai
    Mar 19, 2019 at 9:10
  • @Tensibai hi mate. thanks for responding. i am still new to docker. so i am a bit confused with your explanation. could you please explain in more detail what you mean, possibly give examples. thank you Mar 19, 2019 at 15:10
  • What I mean is: Copy and Paste the full output after your docker command in your question, edit it, without it we can't help or explain what is going wrong without divination.
    – Tensibai
    Mar 19, 2019 at 15:34

1 Answer 1


Don't quote the command you're trying to run, just do:

docker run --rm -it -v ~/Users/mow/Documents/devFolder/testdev:/app testdev_php php ./vendor/bin/phpunit

Your image is looking for a file called "php ./vendor/bin/phpunit" instead of looking for "php" and passing everything else on the line to it.

This is the real reason docker requires all your parameters before the image, because the parameter after the image is the command and everything after it is parameters to that command - don't quote everything.

The Dockerfile equivalent is:

ENTRYPOINT ["/init","parameter1","parameter2","parameter3"]

If it still doesn't work, check the parent Dockerfiles for the location of "php"

docker run --rm -it -v ~/Users/mow/Documents/devFolder/testdev:/app testdev_php /usr/local/bin/php ./vendor/bin/phpunit

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.