Reputation: 1253
I want to dockerize my laravel application but I am getting this error
ERROR: for backend_php_1 Cannot start service php: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "entrypoint.sh": executable file not found in $PATH: unknown
Dockerfile
FROM php:8.2 as php
RUN apt-get update -y
RUN apt-get install -y unzip libpq-dev libcurl4-gnutls-dev
RUN docker-php-ext-install pdo pdo_mysql bcmath
#RUN pecl install -o -f redis \
# && rm -rf /tmp/pear \
# && docker-php-ext-enable redis
WORKDIR /var/www
COPY . .
COPY --from=composer:2.7.4 /usr/bin/composer /usr/bin/composer
ENV PORT=8000
ENTRYPOINT [ "entrypoint.sh" ]
docker-compose
version: "3.8"
services:
# PHP Service
php:
build:
context: .
target: php
args:
- APP_ENV=${APP_ENV}
environment:
- APP_ENV=${APP_ENV}
- CONTAINER_ROLE=app
working_dir: /var/www
volumes:
- ./:/var/www
ports:
- 8000:8000
depends_on:
- database
volumes:
db-data: ~
entrypoint.sh
#!/bin/bash
if [ ! -f "vendor/autoload.php" ]; then
composer install --no-progress --no-interaction
fi
if [ ! -f ".env" ]; then
echo "Creating env file for env $APP_ENV"
cp .env.example .env
else
echo "env file exists."
fi
role=${CONTAINER_ROLE:-app}
echo role
if [ "$role" = "app" ]; then
php artisan migrate
php artisan key:generate
php artisan cache:clear
php artisan config:clear
php artisan route:clear
php artisan serve --port=$PORT --host=0.0.0.0 --env=.env
exec docker-php-entrypoint "$@"
fi
Upvotes: 0
Views: 422
Reputation: 6534
It looks like there might be a couple of things wrong.
Update your ENTRYPOINT
as follows:
ENTRYPOINT [ "./entrypoint.sh" ]
This (the ./
before the filename) is to cater for the fact that the /var/www
is not on your execution path.
This should resolve the executable file not found in $PATH
error.
You should also ensure that the entrypoint.sh
is executable (on the host!).
chmod u+x entrypoint.sh
On the host you'd then have something like this (The x
on the line for entrypoint.sh
is important.):
-rw-rw-r-- 1 423 Apr 25 06:09 docker-compose.yml
-rw-rw-r-- 1 289 Apr 25 06:10 Dockerfile
-rwxrw-r-- 1 615 Apr 25 06:04 entrypoint.sh
You need this because your docker-compose.yml
is mounting the current directory onto the image at /var/www
. So when the container runs the entrypoint.sh
it's actually running the one from the volume mount rather than the one copied onto the image.
This should resolve the permission denied
error.
Upvotes: 1