Live Docker NocoDB Django Postgres Project:
1. Docker Management
General overview and run commands (repo/README.md)
Public demo
Only accessible from NGINX_ALLOW_EXTERNAL_IP_RANGE (per Github secrets: school network or VPN)
Production PowerPC (ppc64le) server:
- https://BRANCHNAME-www.launch.rentals for
presentation_frontendservice - https://BRANCHNAME-www.launch.rentals/api for
presentation_backendservice - https://BRANCHNAME-company.launch.rentals for
company_admin_frontendservice - https://BRANCHNAME-company.launch.rentals/api for
company_admin_backendservice - alternative access using IP: 147.175.146.249, includes HTTP redirect and HTTPS (let's encrypt with manual rotation for now)
Local development setup
Recommendation
- Use Linux, WSL2 or Virtual Machine(Linux).
- When using WSL2 add repo inside Ubuntu connect to WSL2 with Visual Studio Code.
- Run docker commands inside WSL2 or Virtual Machine(Linux) terminal
First time setup
- Clone repo:
git clone https://github.com/fiitka/SmartRent.git cd SmartRent- Force Windows Git to not be CRLF but LF for Docker Shell Scripts to work:
echo "core.autocrlf=false" >> .git/config ; git rm --cached -r . ; git reset --hard - Go to a branch where you will develop:
git checkout -b dev-<your-github-username> - Set environment variables for all Docker services:
cp .env.example .env+ FILL IN THE BLANK VARIABLES WITH RANDOM VALUES - Just in case: Stop and remove all remaining Docker containers and networks prefixed with "launchrentals-":
docker stop $(docker ps -a -q -f name=launchrentals-) ; docker rm -f $(docker ps -a -q -f name=launchrentals-) ; docker network rm $(docker network ls -q -f name=launchrentals_) - Start the service chain:
docker compose --profile dev up -din the root directory (-dfor detached mode) - Wait for
nginxservice to be up and running (last in chain) - If working on frontend, make sure to
docker exec -it launchrentals-company_admin_frontend-1 /bin/bashordocker exec -it launchrentals-presentation_frontend-1 /bin/bashinto your frontend instance and runnpm run build-ci-prodmanually to generate build files, this is manual as it can take up to 15 minutes and applies to both frontends (presentation and company)
Often used: Restart after minor config changes, inconsistencies or computer reboot:
- Turn off:
docker compose down - Stop and remove all remaining Docker containers and networks prefixed with "launchrentals-":
docker stop $(docker ps -a -q -f name=launchrentals-) ; docker rm -f $(docker ps -a -q -f name=launchrentals-) ; docker network rm $(docker network ls -q -f name=launchrentals_) - Turn on again:
docker compose --profile dev up -d
Here it is in one line (you will be copy-pasting this a lot, recommended to add to .bashrc as an alias):
docker compose down ; docker stop $(docker ps -a -q -f name=launchrentals-) ; docker rm -f $(docker ps -a -q -f name=launchrentals-) ; docker network rm $(docker network ls -q -f name=launchrentals_) ; docker compose --profile dev up -d
Also often used: Rebuild after major changes (especially if package.json changed on frontend!):
- Turn off:
docker compose down - Stop and remove all remaining Docker containers and networks prefixed with "launchrentals-":
docker stop $(docker ps -a -q -f name=launchrentals-) ; docker rm -f $(docker ps -a -q -f name=launchrentals-) ; docker network rm $(docker network ls -q -f name=launchrentals_) - Important step - Rebuild without cache:
docker compose build --no-cache - Turn on:
docker compose --profile dev up -d
Here it is in one line (you will be copy-pasting this a lot, recommended to add to .bashrc as an alias):
docker compose down ; docker stop $(docker ps -a -q -f name=launchrentals-) ; docker rm -f $(docker ps -a -q -f name=launchrentals-) ; docker network rm $(docker network ls -q -f name=launchrentals_) ; docker compose build --no-cache ; docker compose --profile dev up -d
Also useful if you're only changing nginx configuration (nginx.template.conf) locally may be this selective restart:
docker compose -p launchrentals stop nginx_reverse_proxy && docker compose -p launchrentals build nginx_reverse_proxy && docker compose -p launchrentals build nginx-dev-reconfig && docker compose -p launchrentals up -d nginx-dev-reconfig && docker compose -p launchrentals up -d nginx_reverse_proxy
If broken: Purge all containers and images (WARNING: this will remove !!!ALL!!! containers on your machine):
- Consider running a slightly less drastic rendition of these commands instead if you have other containers or have them backed up first! With the commands below they will get removed!
- Stop and remove Docker containers then remove Docker images:
docker stop $(docker ps -a -q) ; docker rm -f $(docker ps -a -q) ; docker rmi $(docker images -q) - Afterwards remove all Docker volumes and Docker networks:
docker system prune -a --volumes --force - Start again from docker-compose.yml like fresh install:
docker compose --profile dev up -d
For debugging:
docker container ls -ato get container names and idsdocker compose logs -fto see logs ordocker logs container_id_goes_heredocker exec -it <container-name> /bin/bashto get bash in the container, if no such command then try/bin/shinstead
Service versions and usage
These are the versions Docker Compose uses:
- Database:
mariadb v11.7.2(accessed only by Django backend) - Backend:
python v3.12+Django v5.1.2(uses database, used by nginx/api/) - Frontend:
node v20.18.0+Nuxt+express v^4.21.1(uses nginx/api/for backend, used by nginx/) - Reverse proxy:
nginx v1.27.2(used to access the services under a single domain and add SSL)
If you won't use Docker, you need to (seriously, JUST USE DOCKER!!! or it will be painful...):
- install these versions yourself - see
Dockerfilein each service for instructions - apply environment variables in
.envfile - only run company services or somehow resolve conflicts in database/frontend/backend ports running on same host
- presentation requres company database and presentation database as well, company only company database
- change ports leading to database in each backend
- change ports and domains in
nginx.conflinking to them
- start all services except nginx with relevant environment value mapping (see
docker-compose.ymlenvironment parts) - run
nginx-entrypoint.sh(make sure it points to correct nginx path) to start nginx
What you should know
- Before doing anything in a specific service,
cdinto it. - Django uses live data from the database and reacts to local changes in the code. No wildcard domains due to Django-related issues for now. Django accesses the database using information in
settings.pylinking to environment variables used indocker-compose.ymllinking to.envin root of the repository. - Nuxt dist is built only once, then it is served statically by express through nginx
/route (no live editing because of ppc64le not supportingng servedependencies). You can use local developement outside docker, while refering to backend running in docker or update the running Docker usingng build(by recreatingdist) at any time. Please implement routes found on/api/*on the backend side, allowlocalhostdomains depending onDEV_ENVvariable similar toALLOWED_HOSTSin Django'ssettings.py(not finalized). - Database uses volume storage on host machine, we will need to work on migrations which will be applied on every startup.
- Thanks to nginx you can use local domains (localhost) or public IPs (147.175.146.249 for production server, also available on https://launch.rentals for
presentation_*and https://company.launch.rentals forcompany_admin_*) to refer to frontend and backend running in Docker with the exception of database which should only be accessed from inside Docker network by Django. - Production server is configured to use untrusted SSL certificates for now due to
certbotissues.
Folder structure
nginx_sslcontains certificates for local development, reverse proxy configurationnginx.confis in the root directory.presentation_backendcontains Django backend for Public Presentation including aDockerfile.company_backendcontains Django backend for Company Administration including aDockerfile.presentation_frontendcontains Nuxt frontend for Public Presentation including aDockerfile.company_frontendcontains Nuxt frontend for Company Administration including aDockerfile.- Database volumes are stored by Docker separately in
company_admin_dbdataandpresentation_dbdata; usedocker volume inspectto find the location on your host machine.