Docker Compose to set up and run a Django/PostgreSQL app
To create Django project
$ docker-compose run web django-admin startproject project_name .
If in linux: Change the ownership of the new files in the host
$ sudo chown -R $USER:$USER .
$ docker-compose run web chmod -R 777 .
Replace the DATABASES = ... with the following:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'postgres',
'USER': 'postgres',
'HOST': 'db',
'PORT': 5432,
}
}
$ docker-compose up
$ docker exec -it <container-name> /bin/bash
Inside the container To install an venv and active it
$ virtualenv venv -p python
$ source venv/bin/activate
$ pip install -r requirements.txt
$ python manage.py migrate
$ python manage.py createsuperuser
$ docker-compose down
- Add the app
- Add the model
- Add the app to the installed Apps
- Make migrations
- add the schema folder
- add the query @see: links.schemes.link.query
- add the mutation @see: links.schemes.link.mutation
- add the query and the mutation to the main schema in the root project
after starting the server visit graphql
- to obtain the token use createUser mutation
- with authorization use Insomnia clint or postman and set the Authorization in the Header to jwt