Reputation:
I have a website that uses the sites framework to basically have two different domains serving the same Django project. In production, this is served through a Docker container (including an nginx server). What I would ideally do is have both sites be served from one single Docker container. Is this possible? The websites share the same database so that would be no problem, but what I am not able to figure out is how I can add another "web" instance to the same docker container using the same port (likely impossible). Are there other ways?
Spinning up two docker containers on the same server would also be fine, but again I'd have to use the same ports which causes conflicts.
FYI here is the docker-compose file:
version: '3'
services:
nginx:
image: nginx:latest
ports:
- 80:80
volumes:
- ./src:/src
- ./config/nginx:/etc/nginx/conf.d
depends_on:
- web
web:
build: .
depends_on:
- db
volumes:
- ./src:/src
expose:
- 80
db:
image: postgres:latest
Upvotes: 1
Views: 883
Reputation: 3018
Run 2 containers with Django listening on port 80 for ex. in their respective containers. Map host ports 8081 and 8082 to containers port 80 respectively. Configure nginx to listen on port 80 and have two server blocks to redirect it to either of the domain names using and based on the server name in server block. OR configure nginx with two server blocks redirecting to respective containers directly using upstream directive.
Upvotes: 2