php exec内置shell命令在Alpine中无法在Docker init脚本上工作[关闭]

odopli94  于 2023-11-16  发布在  PHP
关注(0)|答案(1)|浏览(110)

**已关闭。**此问题为not reproducible or was caused by typos。目前不接受回答。

这个问题是由错字或无法再重现的问题引起的。虽然类似的问题在这里可能是on-topic,但这个问题的解决方式不太可能帮助未来的读者。
3天前关闭。
Improve this question
我有这个简单的shell脚本来启动Docker中的laravel应用程序:

#!/bin/sh

set -ex
# generate the key if it does not already exist
case `grep APP_KEY .env | sed -e 's/APP_KEY=\s*//'` in
    'base64:'*)
        echo "artisan key already exists...";;
    *)
        echo "generating artisan key..."
        php artisan key:generate;;
esac
# create or update database
echo "create or update database..."
php artisan migrate --force
echo "starting server"
exec "/usr/local/bin/php artisan serve --host=0.0.0.0"

字符串
php artisan migrate工作正常,所以php在PATH中,但行exec "/usr/local/bin/php artisan serve --host=0.0.0.0"(w/或w/o/usr/local/bin路径)显示:

/var/www/docker_init.sh: exec: line 16: /usr/local/bin/php artisan serve --host=0.0.0.0: not found


Docker文件包含:

FROM php:8.2-fpm-alpine

# Arguments defined in docker-compose.yml
ARG user=fcms
ARG uid=1000

# install helper for installing php extensions
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
# install php extensions
RUN chmod +x /usr/local/bin/install-php-extensions && \
   install-php-extensions @composer pdo_mysql exif pcntl gd imagick

# Set working directory
WORKDIR /var/www

# Create system user to run Composer and Artisan Commands
RUN addgroup -S $user && \
    adduser -G $user -G www-data -G root -u $uid -h /home/$user -S $user && \
    mkdir -p /home/$user/.composer && \
    chown -R $user:$user /home/$user
# Copy the fcms code
COPY --chown=$user:www-data . .
RUN \
    # move the right init file (which execs php artisan serve at the end)
    mv docker/apache/init.artisan.sh ./docker_init.sh && \
    # clean unused folders and blocking files
    rm -rf docker vendor composer.lock .git && \
    # Install everything
    composer install --no-dev

# Set user
USER $user

HEALTHCHECK --interval=5m --timeout=3s --start-period=10s \
  CMD curl -f http://localhost/ || exit 1

CMD ["/var/www/docker_init.sh"]


其中docker_init.sh是上面的脚本。最后一件事,运行:

docker run -it fcms.artisan php artisan serve --host=0.0.0.0


效果很好。
我不明白“执行”有什么不对...

dxxyhpgq

dxxyhpgq1#

正如@DavidMaze评论所提供的,问题是我在exec命令周围添加了双引号。删除它们,它开始像魔法一样工作

相关问题