Skip to content

Instantly share code, notes, and snippets.

@jkleinkauff
Created October 28, 2021 15:12
Show Gist options
  • Save jkleinkauff/9fe705505f941e0b44fd16c947196468 to your computer and use it in GitHub Desktop.
Save jkleinkauff/9fe705505f941e0b44fd16c947196468 to your computer and use it in GitHub Desktop.
Debug Docker Container
docker exec -it <container> /bin/bash
# Run the following commands inside the container
apt update
apt install -y gdb
apt install -y net-tools
pip install debugpy
# Find the PID for the Flask process. Always use the first that appear on the list
ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 14:09 ? 00:00:00 bash /app/docker/docker-bootstrap.sh app
root 6 1 4 14:09 ? 00:00:04 /usr/local/bin/python /usr/bin/flask run -p 8088 --with-threads --reload --debugger --host=0.0.0.0
root 10 6 7 14:09 ? 00:00:07 /usr/local/bin/python /usr/bin/flask run -p 8088 --with-threads --reload --debugger --host=0.0.0.0
# Inject debugpy into the running Flask process. In this case PID 6.
python3 -m debugpy --listen 0.0.0.0:5678 --pid 6
# Verify that debugpy is listening on port 5678
netstat -tunap
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:5678 0.0.0.0:* LISTEN 462/python
tcp 0 0 0.0.0.0:8088 0.0.0.0:* LISTEN 6/python
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment