Zend Framework 3骨架项目docker-compose up启动卡住求助
Hey there, let's work through this issue together—seeing that Apache startup notice but the container seems stuck is super common with PHP framework setups like Zend Framework 3. Here's how to diagnose and fix it:
First: Confirm if the Container is Actually Stuck
That line zf_1 | [Tue Apr 17 21:39:18.715358 2018] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND' is actually Apache confirming it's running in foreground mode—it's not an error. The "stuck" feeling usually comes from ZF3 not finishing initialization, or Apache not serving the ZF3 app correctly.
Try these quick checks:
- Open a new terminal window and run
docker-compose exec zf bashto jump into the running container. If this works, the container is alive—just not serving the app as expected. - Inside the container, check Apache's error logs for clues:
cat /var/log/apache2/error.log - Try accessing
http://localhost:8080in your browser—if you get a 404 or ZF3 error page, the issue is with ZF3 configuration, not the container being stuck.
Fix 1: Ensure Your Dockerfile Has ZF3 Required Dependencies & Apache Config
Your docker-compose.yml points to a Dockerfile, which is likely missing critical setup for ZF3. Here's a minimal working Dockerfile snippet to reference:
FROM php:7.4-apache # Install ZF3 required PHP extensions RUN docker-php-ext-install mbstring pdo pdo_mysql RUN a2enmod rewrite # Enable mod_rewrite for ZF3's routing # Set Apache DocumentRoot to ZF3's public directory RUN sed -i 's/DocumentRoot \/var\/www\/html/DocumentRoot \/var\/www\/public/' /etc/apache2/sites-available/000-default.conf # Install Composer (for ZF3 dependency management) RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" RUN php composer-setup.php --install-dir=/usr/local/bin --filename=composer RUN php -r "unlink('composer-setup.php');"
If your Dockerfile doesn't have these pieces, Apache might be pointing to the wrong directory, or ZF3 might be missing required extensions to run.
Fix 2: Add Initialization Steps to Docker Compose
If your ZF3 project hasn't had dependencies installed yet, the container will start Apache but ZF3 won't be ready. Modify your docker-compose.yml to run Composer install before starting Apache:
zf: build: . dockerfile: Dockerfile ports: - "8080:80" volumes: - .:/var/www command: bash -c "composer install --no-interaction && apache2 -D FOREGROUND"
This ensures all ZF3 dependencies are installed before Apache starts, so the app is ready to serve.
Fix 3: Force Reset the Container (For Stuck States)
If you've tried the above and the container still won't behave, reset it completely:
- Stop and remove the container (and volumes to clear cached data):
docker-compose down -v - Rebuild the image without cached layers (to pick up Dockerfile changes):
docker-compose build --no-cache - Restart the container:
docker-compose up
About docker-compose stop
If the container is unresponsive to docker-compose stop, use docker-compose kill zf to force-stop it, then run docker-compose down to clean up. Avoid using kill regularly, but it's useful for stuck containers.
内容的提问来源于stack exchange,提问作者ci ci

