Dockerized boilerplate. Ngnix server + PostgreSQL database + Django / DRF API backend + React frontend.
Inspired by this and that.
During development, used SQLite + Django + React. In deployment, used Ngnix + PostgreSQL + Django.
Backend used:
- Django 3.0
- django-rest-framework for REST APIs
- django-rest-framework-simplejwt for authentication
Frontend used:
- React 16.13.1
- Redux with Redux-Saga for state management
- axios for HTTP client
- MATERIAL-UI for UI
- FORMIK for the Login form
- Enzyme for testing
- Docker
- docker-compose
-
docker-compose upwill build the image and run the container. -
After running, you can see frontend at http://127.0.0.1:3000/ and backend at http://127.0.0.1:8000/.
(Django built-in admin page at http://127.0.0.1:8000/api/admin/) -
If you want to add a new npm package to the frontend, use
docker-compose exec frontend yarn add ...or run./frontend/fexec.sh yarn add ....
(fexec.sh is just a wrapper for the former) -
Similarly, if you want to add a new python package to the backend, use
docker-compose exec backend pip install ...or run./backend/bexec.sh pip install ....
Save dependencies in requirements.txt.pipdoesn't care about requirements.txt so you have to add dependency manually in the file.You can have a dedicated shell by running
docker-compose exec service_name sh. -
After you've added/modified models in the backend, you need to run database migration.
docker-compose exec backend python manage.py makemigrationsanddocker-compose exec backend python manage.py migratewill compile migrations and migrate. Instead, you can rundocker-compose up --no-deps --build backendto rebuildbackendimage since it automatically runs migrations during the build.
./build_front.shwill build React frontend and put files into./backend/front_builddirectory. This should take a while.docker-compose -f docker-compose.prod.yml upwill build the image and run the container. While building, collecting Django static files, migrating PostgreSQL database, and configuring nginx server is done behind the scenes.- If it's successful, you can see the nginx server running at http://localhost. Django backend is served by gunicorn and configured as a reverse proxy in nginx configuration.
- Django built-in admin page is at http://localhost/api/auth and you can log in with email:
dev@test.com, password:devPass1!.
This user is a superadmin and created automatically during the build of the docker image. - See .env.prod for production environment variables.
Made with ❤️ in Docker.