无法启动php服务:无法为容器创建任务:无法创建shim任务

问题描述 投票:0回答:1

我想对我的 Laravel 应用程序进行 dockerize,但收到此错误

错误:对于 backend_php_1 无法启动服务 php:无法为容器创建任务:无法创建 shim 任务:OCI 运行时创建失败:runc 创建失败:无法启动容器进程:exec:“entrypoint.sh”:找不到可执行文件在 $PATH 中:未知

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: ~

入口点.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
laravel docker docker-compose dockerfile entry-point
1个回答
0
投票

看起来可能有一些问题。

路径

按如下方式更新您的

ENTRYPOINT

ENTRYPOINT [ "./entrypoint.sh" ]

这(文件名之前的

./
)是为了满足
/var/www
不在您的执行路径上的事实。

这应该可以解决

executable file not found in $PATH
错误。

权限

您还应该确保

entrypoint.sh
可执行(在主机上!)。

chmod u+x entrypoint.sh

在主机上,您会看到类似这样的内容(

x
线上的
entrypoint.sh
很重要。):

-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

您需要这个,因为您的

docker-compose.yml
正在将当前目录安装到
/var/www
处的图像上。因此,当容器运行
entrypoint.sh
时,它实际上是运行卷挂载中的那个,而不是复制到映像上的那个。

这应该可以解决

permission denied
错误。

© www.soinside.com 2019 - 2024. All rights reserved.