构建Laravel应用Docker镜像时遇oniguruma依赖缺失错误求助
Hey there, let's get that Docker build error sorted out quickly! The problem here is that the mbstring PHP extension depends on the oniguruma regex library, which isn't included in the base php:7 Docker image by default. When you try to install mbstring via docker-php-ext-install, it can't find the required oniguruma files, hence the error.
Here's the fix:
You just need to add the oniguruma development package (called libonig-dev in Debian/Ubuntu-based images) to your apt-get install command before installing the PHP extensions.
Modified Dockerfile:
FROM php:7 RUN apt-get update -y && apt-get install -y openssl zip unzip git libonig-dev RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer RUN docker-php-ext-install pdo mbstring WORKDIR /app COPY app /app # this copies all the app files to a folder called `app` RUN composer install CMD php artisan serve --host=0.0.0.0 --port=8000 EXPOSE 8000
What changed?
- Added
libonig-devto the list of packages installed viaapt-get— this provides the header files and libraries needed to compile thembstringextension. - All other steps remain the same as your original Dockerfile.
Now re-run your build command:
sudo docker build -t test .
This should resolve the "No package 'oniguruma' found" error and successfully build your Laravel Docker image.
内容的提问来源于stack exchange,提问作者Amy Murphy

