I got error: /usr/local/bin/docker-php-entrypoint: 9: exec: ./vendor/bin/phpunit: not found

Hi folk,

Before that, I’m new to Docker. I need help with this problem. I got the error when I ran this docker compose run --build --rm server ./vendor/bin/phpunit tests/HelloWorldTest.php, The expected output when I run that compose should be like this:

Hello, Docker!PHPUnit 9.6.13 by Sebastian Bergmann and contributors.

. 1 / 1 (100%)

Time: 00:00.003, Memory: 4.00 MB

OK (1 test, 1 assertion)

But l got this error: /usr/local/bin/docker-php-entrypoint: 9: exec: ./vendor/bin/phpunit: not found. Please help me how to solve this. I’ve tried to find the solution but can’t find it.

Here is my composer.json code:
{ "require-dev": { "phpunit/phpunit": "^9.6" } } .

Missing relevant parts are Dockerfile and docker-compose.yml

Can you tell me more details @bluepuma77, please? I’ve try figure it out since morning and I’m still struggling.

Here is my Dockerfile setup:

syntax=docker/dockerfile:1

FROM composer:lts as prod-deps
WORKDIR /app
RUN --mount=type=bind,source=./composer.json,target=composer.json
–mount=type=bind,source=./composer.lock,target=composer.lock
–mount=type=cache,target=/tmp/cache
composer install --no-dev --no-interaction

FROM composer:lts as dev-deps
WORKDIR /app
RUN --mount=type=bind,source=./composer.json,target=composer.json
–mount=type=bind,source=./composer.lock,target=composer.lock
–mount=type=cache,target=/tmp/cache
composer install --no-interaction

FROM php:8.2-apache as base
RUN docker-php-ext-install pdo pdo_mysql
COPY ./src /var/www/html

FROM base as development
COPY ./tests /var/www/html/tests
RUN mv “$PHP_INI_DIR/php.ini-development” “$PHP_INI_DIR/php.ini”
COPY --from=dev-deps app/vendor/ /var/www/html/vendor

FROM base as final
RUN mv “$PHP_INI_DIR/php.ini-production” “$PHP_INI_DIR/php.ini”
COPY --from=prod-deps app/vendor/ /var/www/html/vendor
USER www-data

Here is my compose.yml setup:

services:
server:
build:
context: .
ports:
- 9000:80
depends_on:
db:
condition: service_healthy
secrets:
- db-password
environment:
- PASSWORD_FILE_PATH=/run/secrets/db-password
- DB_HOST=db
- DB_NAME=example
- DB_USER=root
develop:
watch:
- action: sync
path: ./src
target: /var/www/html
db:
image: mariadb
restart: always
user: root
secrets:
- db-password
volumes:
- db-data:/var/lib/mysql
environment:
- MARIADB_ROOT_PASSWORD_FILE=/run/secrets/db-password
- MARIADB_DATABASE=example
expose:
- 3306
healthcheck:
test: [“CMD”, “/usr/local/bin/healthcheck.sh”, “–su-mysql”, “–connect”, “–innodb_initialized”]
interval: 10s
timeout: 5s
retries: 5
phpmyadmin:
image: phpmyadmin
ports:
- 8080:80
depends_on:
- db
environment:
- PMA_HOST=db
volumes:
db-data:
secrets:
db-password:
file: db/password.txt

Can you tell me please. Thank you so much.

I would probably try to start the container with

docker run -it <image> sh

and search inside for the missing executable.

@nurularifin
Hope you have solved it! I encounter the exact same error, turns out I didn’t save the change after adding target:development in the compose.yaml.