The way to start a Django project with Docker
- Docker v20.x
- Docker-compose v1.28
- Django v3.x
-
Clone this git repository to your local machine.
-
Install
docker
anddocker-compose
using official documentation. -
Add user to the docker group to run commands without sudo:
sudo usermod -aG docker $USER
-
Update settings in
dev.env
andconfetti/settings/prod.py
(recommended). -
Go to the project root and run:
docker-compose up
- Create Django superuser in the container(in the second shell):
docker-compose exec web python manage.py createsuperuser
- Run tests(optional):
docker-compose exec web python manage.py test
- Navigate to
http://localhost:8000/
.
-
Create and fill
.env
andconfetti/settings/prod.py
. -
Run application:
docker-compose -f docker-compose.prod.yml up
-
Generate certificates(see next section).
-
Navigate to
https://localhost/
.
How to generate ssl certificates? Follow this guide.
The simplest way with less headaches:
- ssh to the server and go to the project root, assume that you configured domains properly:
docker-compose -f docker-compose.prod.yml exec nginx sh
- Install certbot:
apk update && apk add certbot certbot-nginx
- Generate certificates, we use volumes so we don't need to copy certs manually, don't forget to commit them or even better exclude them from git tracking:
certbot certonly --nginx # follow instructions
- Update data in
deployment/nginx/app.conf
, and then:
docker-compose -f docker-compose.prod.yml up --build
Ad Hoc docker/docker-compose commands (put in .bash_aliases):
alias dcubn=docker-compose build --no-cache
alias dcub=docker-compose up --build
alias dcu=docker-compose up
โญ๏ธ Thanks everyone who has starred the project, it means a lot!
Happy coding ๐