Set up fallback page for when docker is down

My web-application comes in docker-containers an gets started with docker-compose up. The setup exposes it on port 80, the rest happens inside the containers thanks to traefik etc.

If I start it on a machine where a local webserver like apache is installed, it says "port 80 is already in use" and refuses to start, which is clear. One have to stop the sever. I want to have a fallback/error page, which says "under construction" or whatever while the container are not running (due to an error or during an update or whatever).

So for an update I would have to

  1. docker-compose stop/down
  2. start apache
  3. do my stuff
  4. stop apache
  5. docker-compose up

Now I am wondering if I can simplify this: Is there a possibility to serve the fallback.html in a non-blocking way, or in other words: is it possible to set up apache or use another webserver not to block port 80 and allow another application (docker in this case, but the problem would be the same for every application which serves itself) to use it, but serve it, when the other application didn't?


Solution 1:

  • Expose your application on a different port
  • Configure Apache on the host as a reverse proxy
  • Use the ErrorDocument directive to display your custom info page

This is from my configuration I use for exactly this case:

<VirtualHost *:443>
    ServerName host.example.com

    DocumentRoot /var/www/html
    <Directory />
            Options FollowSymLinks
            AllowOverride None
    </Directory>
    <Directory /var/www/html/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            allow from all
    </Directory>

    ErrorDocument 502 /error_503.php
    ErrorDocument 503 /error_503.php

    ProxyRequests Off
    ProxyPreserveHost On
    ProxyPass             /app/             http://localhost:9090/
    ProxyPassReverse      /app/             http://localhost:9090/

    # ... rest of the configuration
</VirtualHost>

The PHP script shows a different message during scheduled downtimes than outside of it.