Laravel项目Docker构建PHP时出现Error 139问题求助
Hey there, let's work through this Error 139 you're facing while building your PHP Docker image for your Laravel project. Error 139 is almost always a segmentation fault—meaning the process crashed because it tried to access invalid memory. Here are actionable steps to diagnose and fix this:
Common Causes & Solutions
1. Validate Your Dockerfile Completeness & Compatibility
First up, your docker/app.docker file was cut off in your snippet, so make sure it's fully written and uses valid commands. Segfaults often pop up when installing incompatible PHP extensions or running broken shell commands.
- Double-check extension installation lines (like
docker-php-ext-installorpecl install). For example, if you're using a newer PHP version (8.0+), some older extensions might not be supported and can cause crashes. Stick to official, maintained extensions for your base PHP image. - Ensure you're not missing critical dependencies for extensions. For Laravel, you'll need things like
pdo_mysql,mbstring,exif,pcntl, andbcmath—make sure each is installed with the correct prerequisites (e.g.,libpng-devfor the GD extension).
2. Check Architecture Compatibility
If you're on an ARM-based system (like Apple Silicon M1/M2), using Docker images that don't support multi-architecture can trigger segfaults.
- Try adding the
--platform linux/amd64flag to your build command to force x86_64 emulation:docker-compose build --platform linux/amd64 php - Alternatively, use official PHP base images that support ARM (most recent official
phpimages are multi-arch now, likephp:8.2-fpm-alpine).
3. Simplify & Debug the Build Process
Narrow down exactly which step in your Dockerfile is causing the crash by stripping it back to basics:
- Start with a minimal Dockerfile (just the base PHP image + copying your Laravel files) and build it. If it works, add one command at a time (extension installs, composer install, etc.) until you hit the error. This will tell you exactly what's triggering the segfault.
- Run the build with verbose output to get more details:
The plain progress output will show you each command as it runs, making it easier to spot where the crash happens.docker-compose build --no-cache --progress=plain php
4. Fix File Permissions & Volume Usage
While volumes are great for runtime, relying on them during build can cause permission issues that lead to unexpected crashes:
- In your Dockerfile, use
COPY . /var/wwwto copy your Laravel project files into the image instead of relying on the volume mount during build. Volumes are for live code updates when running containers, not for building the image. - Ensure your project files have proper permissions. You can set them in the Dockerfile with:
RUN chown -R www-data:www-data /var/www
5. Update Docker to the Latest Version
Outdated Docker versions can have bugs that cause segfaults during builds. Update Docker Desktop (or Docker Engine on Linux) to the latest stable release, then try rebuilding your image.
Next Steps
If none of these fix the issue, share the full content of your docker/app.docker file—this will help pinpoint the exact command or configuration causing the crash.
内容的提问来源于stack exchange,提问作者sseggio

