serversideup / docker-php

đŸŗ Production-ready Docker images for PHP. Optimized for Laravel, WordPress, and more!
https://serversideup.net/open-source/docker-php/
GNU General Public License v3.0
1.65k stars 108 forks source link

Apache container fails to restart #365

Closed slackernrrd closed 3 months ago

slackernrrd commented 3 months ago

Affected Docker Images

serversideup/php:8.2-fpm-apache-v3.1.1

Current Behavior

If the container is stopped and then the same container is started (instead of recreating it) the container will fail to start, giving the following output:

👉 [NOTICE]: Improve PHP performance by setting PHP_OPCACHE_ENABLE=1 (recommended for production).
ln: failed to create symbolic link '/etc/apache2/conf-enabled/remoteip.conf': File exists
ln: failed to create symbolic link '/etc/apache2/conf-enabled/security.conf': File exists
ln: failed to create symbolic link '/etc/apache2/conf-enabled/serversideup.conf': File exists
ℹī¸ NOTICE (init-webserver-config): Enabling Apache site with SSL "off"...
ln: failed to create symbolic link '/etc/apache2/sites-enabled/ssl-off.conf': File exists
s6-rc: warning: unable to start service 10-init-webserver-config: command exited 1
/run/s6/basedir/scripts/rc.init: warning: s6-rc failed to properly bring all the services up! Check your logs (in /run/uncaught-logs/current if you have in-container logging) for more information.
/run/s6/basedir/scripts/rc.init: fatal: stopping the container.

This also happens if docker itself is restarted, since docker tries to restore all containers that were running when it stopped. This happened to me when my host server was rebooted due to systems upgrades.

Expected Behavior

The container should start normally.

Steps To Reproduce

  1. docker run -p 8080:8080 --name ssup-apache-fpm -d serversideup/php:8.2-fpm-apache-v3.1.1
  2. docker stop ssup-apache-fpm
  3. docker start ssup-apache-fpm

Anything else?

The error seems to be with 10-init-webserver-config. Examining it, the last command run is ln -s "/etc/apache2/sites-available/ssl-$ssl_mode.conf" "$apache2_enabled_site_path/ssl-$ssl_mode.conf". Since the link already exists, the command fails. The return code of the script the same as the last command's return code (I think?).

A fix might be to add exit 0 after line 153, enable_apache_site "$SSL_MODE".

jaydrogers commented 3 months ago

Thanks for the report!

This could be related to container caching, but I will expand the script to only link it if it's not already enabled 👍

For a workaround, remove your container with docker rm <container-id> and it should work for now

jaydrogers commented 3 months ago

I just pushed up a fix and it's building now (see commit message above).

Once this is finished being built, it will be available on our php-dev repo: https://hub.docker.com/r/serversideup/php-dev/tags

I tested it locally and got good results.

This fix will be made available in our next stable release đŸĨŗ

I greatly appreciate you letting us know about this 👍

slackernrrd commented 3 months ago

Thanks for the quick fix! And for a great image 😄

jaydrogers commented 3 months ago

You bet!

The build completed, so this should give you better behavior:

## Pull the dev image
docker run --name ssup-apache-fpm -d serversideup/php-dev:8.2-fpm-apache

## Stop container
docker stop ssup-apache-fpm

## Start again
docker start ssup-apache-fpm

## View logs
docker logs ssup-apache-fpm
slackernrrd commented 3 months ago

Yeah, that works as expected 😄