Skip to content

Instantly share code, notes, and snippets.

@melvinkcx
Created January 10, 2020 02:57
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save melvinkcx/1cc687acd898a48718ac246716d1cf45 to your computer and use it in GitHub Desktop.
Docker Compose Interactive Mode for Debugging

Interactive Docker Container for Debugging with Compose

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`.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment