Reputation: 1231
Im searching for best practice for multiple nginx containers with tld support. Please consider the following docker-compose file:
frontend:
build:
context: nginx/
hostname: frontend-docker
ports:
- "32777:80"
backend:
build:
context: nginx/
hostname: backend-docker
ports:
- "33777:80"
proxy:
image: nginx
hostname: proxy-docker
links:
- frontend
- backend
ports:
- "80:80"
Description As you see I can access frontend and backend at localhost:32777 and localhost:33777 but when I got to prod I want to access frontend at site.com and backend at backend.site.com. In that case comes proxy
container that holds server_name backend.site.com;
and server_name site.com
and creates revers proxy to http://frontend
and http://backend
My question is should I get rid of proxy container and put server_name
part directly in frontend
and backend
container and even build one container called web
that holds backend and frontend
there.
In general splitting the containers in that way is more suitable in terms of configuration, env variables, build different images and so on.
Upvotes: 1
Views: 805
Reputation: 345
Adressing frontend
and backend
containers directly from the outside most likely won't work because you can't bind port 80 to the host more than once.
If frontend
and backend
are different applications you might want to build images of them with different Dockerfile
s.
While we're at it, you might want to look into a simple loadbalancing solution like https://traefik.io/ as frontend for your containers.
But maybe that's overkill for your current use case and you want to stick with your above configuration.
Upvotes: 1