LoginSignup
5
1

More than 3 years have passed since last update.

Dockerコンテナ内でのgdbエラー対応

Posted at

概要

Dockerコンテナ内でgdbコマンドを使ってCプログラムのデバッグをしようとしたところ,以下のような
warning: Error disabling address space randomization: Operation not permitted
と怒られました.

(gdb) b 5
Breakpoint 1 at 0x117c: file test.c, line 5.
(gdb) r
Starting program: /home/user/dev/test 
warning: Error disabling address space randomization: Operation not permitted

予想がつくとは思いますが雑にいうと,gdbはシステムコールを利用しているが,コンテナの中からは権限が無いためホストマシンのデバイスにアクセスできないらしい.

解決策

システムコールを許可してあげるオプションを付与してあげる.

  • docker run実行時
$ docker run -it --cap-add=SYS_PTRACE --security-opt="seccomp=unconfined" [CONTAINER_NAME] /bin/bash
  • docker-composeでの場合

service下に以下を書いてあげる.

docker-compose.yaml
    cap_add: 
      - "SYS_PTRACE"
    security_opt: 
      - "seccomp=unconfined"

参考記事

5
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
1