When i try to access http://127.0.0.1:8000/admin
, i get this.
my folder structure is :
django-react-nginx
|
|_ _ docker-compose.yml
|
> backend
|
|_ Dockerfile
|
|_ entrypoint.sh
> languages
|
|_ settings.py
> media
> static # This folder appears after running docker-compose -d --build
> nginx
|
|_ default.conf
|
|_ Dockerfile
now
here is the files
Django
settings.py
DEBUG = True
ALLOWED_HOSTS = ['*']
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
Docker file
FROM python:3.8
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
WORKDIR /backend
COPY requirements.txt /backend/
RUN pip install -r requirements.txt && \
pip install --upgrade pip
COPY ./entrypoint.sh /
ENTRYPOINT ["sh", "/entrypoint.sh"]
entrypoint.sh
#!/bin/sh
python manage.py migrate --no-input
python manage.py collectstatic --no-input
gunicorn languages.wsgi:application --bind 0.0.0.0:8000
Nginx
default.conf
upstream django {
server backend:8000;
}
server {
listen 80;
location / {
proxy_pass http://django;
}
location /static/ {
autoindex on;
alias /backend/static;
}
location /media/ {
autoindex on;
alias /backend/static;
}
}
Dockerfile
FROM nginx:1.19.8-alpine
COPY ./default.conf /etc/nginx/conf.d/default.conf
Root Folder
Docker-compose
version: "3.7"
services:
backend:
build: ./backend/languages
stdin_open: true # interactive
tty: true # interactive
restart: "on-failure"
env_file:
.env
volumes:
- ./backend/languages:/backend
- ./backend/languages/static:/backend/static
ports:
- 8000:8000
networks:
- nginx_network
- db_network
depends_on:
- db
db:
image: postgres:11
restart: "on-failure"
environment:
- POSTGRES_DB=postgres
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
volumes:
- postgres_data:/var/lib/postgresql/data/
networks:
- db_network
nginx:
build: ./nginx
restart: always
volumes:
- ./backend/languages:/backend
- ./backend/languages/static:/static
ports:
- 80:80
networks:
- nginx_network
depends_on:
- backend
networks:
nginx_network:
driver: bridge
db_network:
driver: bridge
volumes:
postgres_data:
As mentioned above i am not sure how to make the static files work, they been copied to the folder mentioned above because when i can see the folder created and when i check the logs i get this 165 static files copied to '/backend/static'.