Is there anyway to deploy 2 django projects using docker having different domain?

125 Views Asked by At

I am new to programming world, so basically an average. Since few days, I am beating myself up in order to deploy 2 django projects having different domains with docker, uwsgi and Nginx but somehow I could not. Problem 1: I cant run 2nd nginx docker using port 80. Getting an error of port already in use. Problem 2: If I change the ports and run the app docker and nginx. It doesnt work. Both the domains pointing to Nginx at port 80. As per nginx logs. Problem 3: One domain that is mentioned in allowed hosts of django settings, works fine. And other domain throws a bad request error. Same thing on Vice-versa.

I have read multiple articles saw multiple posts and videos still no help. So Ends up deploying the projects directly on the server using nginx and uswgi. I like the docker technology but had to stop it. There's not much relevant topics available in internet. So asking here with minimum to no hope. Am I missing something? Any points and help relevant to this topic would be appreciated? Thanks in advance

/default.conf

server {
    listen ${LISTEN_PORT}; 
     server_name example.com; 


    location / {
        uwsgi_pass              ${APP_HOST}:${APP_PORT};             
        include                 /etc/nginx/uwsgi_params;
        client_max_body_size    10M;
    
    }
    location /static {
        alias /vol/static;
    }
}

Same configuration of 2nd docker app with different app and port

Nginx docker file

FROM nginxinc/nginx-unprivileged:1-alpine
LABEL maintainer="example.com"

COPY ./default.conf.tpl /etc/nginx/default.conf.tpl
COPY ./uwsgi_params /etc/nginx/uwsgi_params

COPY ./run.sh /run.sh

ENV APP_PORT=9000
ENV APP_HOST=app

ENV LISTEN_PORT=80



USER root

RUN mkdir -p /vol/static && \
    chmod 755 /vol/static && \
    touch /etc/nginx/conf.d/default.conf && \
    chown nginx:nginx /etc/nginx/conf.d/default.conf && \
    chmod +x /run.sh

VOLUME /vol/static

USER nginx

CMD ["/run.sh"]
1

There are 1 best solutions below

1
Ankit On

Finally I figured it out. What I did is I created a network specifying subnets like 10.5.6.0/24 and assigning ipv4 address to each container. Then I used Nginx as a reverse proxy for each project. Docker networks is the way to go. I don't know how feasible is this but works for me.