1.7 Custom Error Pages on Docker Swarm

Hey All,

I'm currently using traefik on our docker swarm clusters and was trying to setup a custom error page for a specific app. I have a static error page that I want to use that's hosted in an S3 bucket and was curious if the features of 1.7 would allow me to just point to the static hosted content in S3 when a the web application gets a 500s level error.

We are initiating traefik with commands on the container:

command:
  - "--web"
  - "--docker.swarmmode=true"
  - "--docker.domain=docker.localhost"

The rest of the hosting is being handled at the application level with docker stack labels. I was wondering if I need to put the rules for the error page on the traefik config itself as a command or if it can be hosted in the application labels. I couldn't readily find the command necessary to invoke these rules on the traefik container command section and I've tried a couple iterations at the application level with no luck.

Here are the labels I had on my application container:

  labels:
    - traefik.frontend.passHostHeader=true
    - traefik.port=${PORT}
    - traefik.path.frontend.rule=Host:${HOST}
    - traefik.backend.healthcheck.interval=30s
    - traefik.backend.healthcheck.timeout=5s
    - traefik.docker.network=docker-gateway
    - traefik.frontend.errors.app.backend=error
    - traefik.frontend.errors.app.status=404-599
    - traefik.frontend.errors.app.query=/index.htm
    - traefik.backend.error.server.error.url=my-error-page-bucket.s3.amazonaws.com

I have since changed to hosting the static error page in an nginx container but now when the app that I want the error page to be served for when its not available isn't working.

Just looking for clarification on how the actual docker labels work so I can hopefully configure what I have properly

So now I'm using these same labels on the front end app that I want to have show an error page when its down.

- traefik.frontend.errors.app.backend=error
- traefik.frontend.errors.app.status=404-599
- traefik.frontend.errors.app.query=/

But now the nginx container that is hosting the static page has label traeifk.backend="error".

Couple questions does the backend need to be the dynamic name that shows up the traefik GUI? Because in the GUI it has backend-{docker-stack-name}-error-error. I just assumed everything after backend was the actual traefik service name.

Also if the container is actually down will the rules actually work? I've been trying to test this by taking down the container that I want to show the error for and it seems like the rules actually aren't there if replicas are set to 0. So that might not be the best way to test but I would think if it was 0/1 that the rules would be there then. Maybe the labels actually need to be on the error page container instead of the app container?

Also what is <NAME> in the labels from the docs. That's probably the most vague item in the docs as it doesn't explain at all what the NAME should be. Is it the service name in the traefik UI? Is it the service name you put in the compose file. I've tried several variations of this including not using name at all because there is one stack overflow topic related to this but I think it was for 1.6. But they had traefik.frontend.errors.network.status etc instead of my labels. Which ones are right? Is it the doc page or the dot notation of whats in the toml example?

I feel like the docs for 1.7 related to swarm are severely lacking as its usually 1 or 2 words for references and the actual use of the labels is hardly explained in most cases. I understand this is open source but I feel like something as easy and redirecting to an error page hosted by nginx would be something most apps would want. Barring upgrading which isn't really an option for our team at this point I feel the options to get answers here have been fairly poor.

1 Like

No body answer? I also don't know what does <NAME> mean.