Debugging Django on Docker on Vagrant with IDE -


i have quite docker stack @ moment, compiled many containers, 1 of running instance of django.

at moment, i'm limited debugging importing logging , using

logger = logging.getlogger(__name__) logger.debug("your variable: " + variablename) 

it's totally inefficient , requires me rebuild docker stack every time want re-evaluate change.

i'm used working in komodo , having robust, step-able debugger @ disposal, can's seem find documents on how wire docker container inside vagrant vm ide (or command line debugger) let me step through code without rebuild.

how can wire debugging ide docker container inside vagrant vm? thanks.

i recommend use docker compose handle , link containers. i'm using docker stack on dev env container - django
- postgres
- nginx

you have synchronize code code inside docker container. that, use volumes command in docker-compose file. here example, 2 containers (django , postgres) :

db:   image: postgres web:   build: .   command: python manage.py runserver 0.0.0.0:8000   volumes:     - .:/webapp   ports:     - "8000:8000"   links:     - db 

this portion of code want. project . synchronized /webapp folder of docker container then, no more need rebuild docker image:

volumes:     - .:/webapp 

then, debug, recommend use pdb, in opinion , best way debug django app, run :

docker-compose -f [path/to/your/docker-compose.yml] --service-ports  [name-of-your-django-container] python manage.py runserver 

e.g :

docker-compose -f django_project/docker-compose.yml --service-ports django python manage.py runserver 

let's debug view :
1. import pdb in view :import pdb
2. add pdb.set_trace() in method or class in view
3. request right url
, able debug through terminal should have :

(pdb) > /webapp/car/views.py(18)get() -> car in serializer.data: 

here tutorial use compose , django docker : quickstart guide: compose , django


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -