patterndockerMinor
running a phpUnit test within a docker container
Viewed 0 times
containerdockerwithinrunningphpunittest
Problem
i want to run a specific version of phpUnit WITHIN a docker container. This container will use a specific version of php. i.e
php:5.6-apache
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:
This returns the error:
i am unclear why it says this because te vendor directory is at the root of my site directory.
this is my dockerfile
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.
php:5.6-apache
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 directoryi 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
ENV S6_OVERLAY_VERSION 1.11.0.1
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
WORKDIR /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.
Solution
Don't quote the command you're trying to run, just do:
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:
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 php ./vendor/bin/phpunitYour 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/phpunitCode Snippets
docker run --rm -it -v ~/Users/mow/Documents/devFolder/testdev:/app testdev_php php ./vendor/bin/phpunitENTRYPOINT ["/init","parameter1","parameter2","parameter3"]docker run --rm -it -v ~/Users/mow/Documents/devFolder/testdev:/app testdev_php /usr/local/bin/php ./vendor/bin/phpunitContext
StackExchange DevOps Q#6659, answer score: 1
Revisions (0)
No revisions yet.