Restart docker reverse proxy at last container

I have three containers:

  • reverse proxy
  • testserver
  • nextcloud server

I want the reverse proxy (nginx) to start at the last container on a startup of the host. When it starts before other container, if fails as the nginx.conf is looking for the other container. If it cannot find them, it fails and I have to manually restart.

Probably there is a chance to adapt the nginx.conf somehow, that is also a possibility, but I dont know how.

I am not sure if it realy is the solution, years ago I when I was using ngnix as a reverse, I don’t remember having that sort of problem with a configuration like this:

Though, it might be possible that nginx had a different behavior back in those days. If I remember correct it had to use proxypass with variables that pointed to the target, as using proxypass with upstream was problematic.

If it’s not the solution, then I would strongy suggest to use Traefik instead. Traefik listens on docker events and registers/unregisters reverse proxy rules depeding of container labels of the target container and its lifecycle.

I realize I forget to answer your leading question.

You can use depends_on for that. But if you adopt your config to be like the snippet from the link, I expect it to overcome the problem already. Note: Swarm deployments ignore depends_on.