Reputation: 9826
I am new to Docker
and setting up docker
to run Django
application using gunicorn
and nginx
my configuration files are
docker-compose.yml
version: '3'
services:
nginx:
image: nginx:latest
container_name: "myapp-nginx"
ports:
- "10080:80"
- "10443:43"
volumes:
- .:/app
- ./config/nginx:/etc/nginx/conf.d
- ./static_cdn:/static
depends_on:
- web
web:
build: .
container_name: "myapp-dev"
command: ./start.sh
volumes:
- .:/app
- ./static_cdn:/static
ports:
- "9010"
depends_on:
- db
expose:
- "9010"
db:
image: postgres
container_name: "myapp-db"
config/nginx/nginx.conf
upstream web {
ip_hash;
server web:9010;
}
server {
location /static {
autoindex on;
alias /static/;
}
location / {
proxy_pass http://web;
}
listen 9010;
server_name localhost;
}
start.sh
#!/usr/bin/env bash
# Start Gunicorn processes
echo --: Starting application build
echo --: Creating migration
python3 manage.py makemigrations
echo ------: makemigrations complete
echo --: Running migration
python3 manage.py migrate
echo ------: migrate complete
echo --: Running collectstatic
python3 manage.py collectstatic <<<yes
echo ------: collectstatic complete
echo --: Starting Gunicorn.
gunicorn koober.wsgi:application \
--bind 0.0.0.0:9010 \
--workers 3
running docker using
docker-compose up --build
It runs successfully with output as
Here gunicorn is successfully started at 0.0.0.0:9010
. But unable to visit the application using browser.
I tried following address in browser
But none of them is working.
Edit 2: output of
docker ps -a
Upvotes: 0
Views: 560
Reputation: 2613
Try with this
upstream web {
ip_hash;
server web:9010;
}
server {
listen 10080;
location / {
proxy_pass http://web;
}
}
Nginx should listen on 10080 port because in your compose file you have exposed port 80 to 10080 port.
and then try http://localhost:10080 or http://machine-ip-address:10080
here is the blog which I have written to explain how Docker + Nginx + Web application work together.
Source code https://github.com/RohanMohite/Docker-Nginx-PHP/blob/master/server_nginx/conf/server.conf
Upvotes: 1