Debbuging a `-slim` image?

オープン
#903 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
25/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
docker, python
領域
devops, tooling

調査の方向性

リポジトリのファイルもテストも指定されていません。まず python:3.11-slim-bookwormpython:3.11-bookworm のイメージビルドを比較し、次に gdb の attach コマンドを再現して、実行ファイルとデバッグシンボルの不一致を調べます。完了条件は、slim イメージに対して py-bt が動作するかを確認し、再現可能なデバッグ方法または制限事項を文書化することです。

索引モデルが issue の本文から書いたものです。

説明

We are hitting a rare deadlock in production that can't be reproduced using debug images.
Only way to debug it is to attach to the production image as the problem happens.
Problem is that production are based on the -slim images.

apt install gdb and python3-dbg is not enough because the python running is built from source and not aligned with what is available in apt.

I've tried to start the corresponding non-slim image but their binaries don't seem to align enough to make gdb happy:

Start python inside -slim image

➡️ My end goal is to run gdb py-bt on this process:
docker run -ti python:3.11-slim-bookworm python3 -c "import time; time.sleep(1000)"

Inside this image there is no chance to debug at all due to missing gdb and debug symbols. This is expected.

Build a debugger image from the corresponding non-slim image.
FROM python:3.11-bookworm

RUN --mount=type=cache,target=/var/cache/apt --mount=type=cache,target=/var/lib/apt \
    apt update -y && \
    apt install -y gdb

docker build -t mydebugpython .

Use the newly built debug image to attach into the first running container

Find the container id and use that to attach to the same pid-namespace.

docker run \
    --cap-add SYS_PTRACE \
    --pid container:15aab7ea5f57 \
    --privileged  \
    -ti \
    --entrypoint bash docker.io/library/mydebugpython
root@bb90d04f8722:/# gdb -q python --pid 1 -ex "py-bt"

Reading symbols from python...
Attaching to program: /usr/local/bin/python, process 1

warning: Build ID mismatch between current exec-file /usr/local/bin/python
and automatically determined exec-file /usr/local/bin/python3.11
exec-file-mismatch handling is currently "ask"

Load new symbol table from "/usr/local/bin/python3.11"? (y or n) y
Reading symbols from /usr/local/bin/python3.11...
Reading symbols from target:/usr/local/bin/../lib/libpython3.11.so.1.0...
(No debugging symbols found in target:/usr/local/bin/../lib/libpython3.11.so.1.0)
Reading symbols from target:/lib/x86_64-linux-gnu/libc.so.6...
Reading symbols from /usr/lib/debug/.build-id/82/ce4e6e4ef08fa58a3535f7437bd3e592db5ac0.debug...
Reading symbols from target:/lib/x86_64-linux-gnu/libm.so.6...
Reading symbols from /usr/lib/debug/.build-id/ea/87e1b3daf095cd53f1f99ab34a88827eccce80.debug...
Reading symbols from target:/lib64/ld-linux-x86-64.so.2...
Reading symbols from /usr/lib/debug/.build-id/38/e7d4a67acf053c794b3b8094e6900b5163f37d.debug...
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
__GI___clock_nanosleep (clock_id=1, flags=1, req=0x7ffd9d9ec458, rem=0x0) at ../sysdeps/unix/sysv/linux/clock_nanosleep.c:71
71	../sysdeps/unix/sysv/linux/clock_nanosleep.c: No such file or directory.
Traceback (most recent call first):
  (unable to read python frame information)    # <--------------   :(

So it seems like the difference of slim and non-slim isn't only the presence of debug symbols or not, but also the binary is built differently?
Is this possible to solve somehow? My knowledge of how python is built and how to operate gdb are only moderate.

主要言語
Dockerfile
スター
2.8k
フォーク
1.1k
平均マージ
3日 1時間
マージ済み PR(30日)
1

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

docker-library/python のほかの issue

docker-library/python の issue をすべて見る

似ている issue

DevOps の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。