No Trafiek doesn’t need Redis, but your NodeJS web site might. So when you enable Redis it is used in NodeJS for sessions for example. However when also Traefik is enabled, all the docker services like web and db are placed in special network proxy so that are isolated from the rest of the world and only accessible via Traefik and each other. But Redis wasn’t placed in the same network so that is why it wasn’t accessible even if it was running and also the web service couldn’t find Redis and NodeJS was crashing.
So placing also Redis in the same network solve all the problems.
So the correct solution is for each project/docker-compose have its own network, and only the web service joins the “proxy” network (as well as the project’s own network)
With your approach there’s a problem, how do you handle the case of you having many projects running on the same server, but the “db” or “redis” are accessible on the global “proxy” network? How does a Wappler project knows it’s connecting to its DB and not some other project’s? There are no guarantees, the hostname of Redis/DB container is the same for every project
redis:
image: 'redis:alpine'
hostname: 'redis' # So every project has same hostname? Disaster waiting to happen
networks:
proxy: ~
volumes:
- 'redis-volume:/data'
The correct solution I mentioned in the 1st paragraph
Very good question. Currently we didn’t deal much with that as you are usually deploying one project per server, but as we move to allowing more projects on the same server, we should definably address this.
So what is your suggestion? Specific network per project? And Traefik giving access to all those networks?
redis:
image: 'redis:alpine' # Remember to set Redis version
hostname: 'redis'
networks:
- default
volumes:
- 'redis-volume:/data'
Web service, relevant excerpt:
web:
networks:
- default
- proxy
The project’s network I named “default”, which would be what docker-compose would create for each project if you didn’t specify the “proxy” network (feel free to edit this name), so the actual real name becomes something like “projectName_default” (docker-compose does this automatically)
So, each service joins the “projectName_default” network, and the web service also joins the global “proxy” network
Well it seems that placing all the docker services in a single traefik proxy network is not a problem at all with multiple projects, as each of their hostname get prefixed with the project name. So it works all fine and seems they can find each other perfectly as well Traefix redirects to the right service