In order for PDB to work in a Docker container, you can use
docker run -it <image_name>
For Docker Compose, add two lines stdin_open: true
and tty: true
into the service of your docker-compose.yml
:
version: '3'
services:
web:
build: .
entrypoint: python manage.py
command: runserver 0.0.0.0:8000
volumes:
- .:/app
ports:
- "8000:8000"
env_file:
- ./.env.staging
stdin_open: true # This
tty: true # This
Run your docker container as usual: docker-compose -f <docker_compose_filename> up -d
To start an interactive session, run docker attach <container_id>. You can get your container id with
docker ps`.