Django Docker start up project
For making new projects with docker and django without using virtual environment Now included vite, postcss, bun, tailwindcss
- First - Clone this repo to your local machine
git clone https://github.com/issamlk1/django-docker - Create .env file and fill it, it's content is inside the file .env.example for development enviroment
- Open terminal from the project file and follow the next steps
First build the docker file
$ docker compose buildThen create the new project
$ docker compose run web django-admin startproject config .- After building the project you need to edit sittings.py to your new database information
change /settings.py From
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}If you kept the postgresql it should look like this (its better to use the .env)
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'myproject',
'USER': 'postgres',
'PASSWORD' : 'postgres',
'HOST': 'postgresql',
'PORT': 5432,
}
}$ docker compose up -d$ docker compose down- To access the docker containers just type this command in your terminal
django
$ docker compose exec -it django zsh postgresql
$ docker compose exec -it postgresql bash- If you added new django packages to your projects make sure to run following command from inside the django container before shutting down
$ pip freeze > requirements.txtThen before running the project again build the project again to download your packages
$ docker compose build web- How do I use mysql database?
- I removed the mysql example from the project, maybe I'll add it later.
Reach out to me at one of the following places!
- Website at
mlk1.com
- MIT license
- Copyright 2019 © mlk1.