Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cglusky/docker-django-react
A local dev full-stack template using docker-compose with Django and React.
https://github.com/cglusky/docker-django-react
django django-rest-framework docker docker-compose fullstack react
Last synced: 4 days ago
JSON representation
A local dev full-stack template using docker-compose with Django and React.
- Host: GitHub
- URL: https://github.com/cglusky/docker-django-react
- Owner: cglusky
- License: mit
- Created: 2020-07-17T16:10:24.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-09-11T16:36:17.000Z (2 months ago)
- Last Synced: 2024-09-12T02:02:27.350Z (2 months ago)
- Topics: django, django-rest-framework, docker, docker-compose, fullstack, react
- Language: Python
- Homepage:
- Size: 4.69 MB
- Stars: 42
- Watchers: 2
- Forks: 16
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# docker-django-react
## Project Status
**Dec 2023**
Although I do not use Django or React these days, I know someone who does. Special thanks to @crhowell for helping me get this updated after three years of neglect. Seems like a few people have found it useful, so we will try to give it a little more love. Latest updates are mostly lessons learned, house keeping and version bumps.## Basics
A slightly opinionated local dev full stack template using docker-compose with Django backend and React frontend; all served behind NGINX. Keeping the full stack in one repo for ease of use. Composed of ideas from multiple tutorials, forum threads and official docs. Nothing original here.
## Main Frameworks/Libraries/Packages
Please see requirements.txt and package.json for full details.
Django
- Django v5
- Django Rest Framework
- Django Rest Framework Simple JWT
- PyTestReact
- Create React App
- Node dev server via Docker LTS alpine image
- Hot reloadPostgress
- Docker v16.1 alpine image
Ngnix
- Docker stable alpine
- Serves Django's static and media files as well. See conf for details.## Notes
Django
- One app created/installed called core
- Custom user stubbed out in the Core app. No additional fields. Just a blank class that inherets AbstractUser. core.User is assigned as AUTH_USER_MODEL
- SimpleJWT is installed but not used.## Fork or Template
Feel free to fork at will but it may be handier as template. The following are the steps I had in mind for using it as a project template:
1. Create a new repo on GitHub without ReadMe
2. On your local dev machine, and in your preferred parent directory:```sh
$> git clone https://github.com/cglusky/docker-django-react.git
$> cd
$> git remote set-url origin
$> git push -u origin master```
### Edit And Rename .env-example
All services expect to read env variables from .env.dev file. Please make sure you review the example and change the name to env.dev. AND that your gitignore handles env files before you commit super secret stuff to a public repo.
### Useful Commands
Build containers. Add -up flag to bring services up after build.
```sh
$> docker compose build
```
Bring containers up. Add -d flag to run output detached from current shell.
```sh
$> docker compose up
```
Bring containers down. Add -v flag to also delete named volumes
```sh
$> docker compose down
```
View logs by service name.
```sh
$> docker compose logs
```
Enter shell for specified container (must be running)
```sh
$> docker exec -it sh
```
### Containers, Services and Ports
| Container | Service | Host Port | Docker Port |
| ---------- | ------- | --------- | ----------- |
| dev-django | django | 8001 | 8000 |
| dev-react | react | 3001 | 3000 |
| dev-db | db | 5432 | 5432 |
| dev-nginx | nginx | 8080 | 80 |### Why NGINX for local dev?
Cross-Origin Resource Sharing(CORS) issues will make your browser sad when you serve your site from different ports as we do with this architecture. Using NGINX to proxy requests/responses to/from the correct container/service/ports helps make your browser happy. And it simulates real world infrastructure as a bonus. So...
Please make all requests from your browser through and NGINX will happily redirect the request and proxy all your services so your browser thinks it's all one and the same protocol/domain/port == CORS bliss.
### Can this be used for production?
This project is focused on making it easier to perform local full stack development. However, it is possible to add new docker compose and docker files to also support production. It's just out of scope for this project. Please have a look in the archives folder for some old production docker files to give you an idea of what worked in the past.