Support for gdb errors in Docker containers

Overview

When I tried to debug a C program using the gdb command in a Docker container, the following warning: Error disabling address space randomization: Operation not permitted I was angry.

(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

As you might expect, gdb uses system calls, but it seems that you cannot access the device of the host machine because you do not have the authority from inside the container.

solution

Option to allow system call will be added.

$ docker run -it --cap-add=SYS_PTRACE --security-opt="seccomp=unconfined" [CONTAINER_NAME] /bin/bash

Write the following under service.

docker-compose.yaml


    cap_add: 
      - "SYS_PTRACE"
    security_opt: 
      - "seccomp=unconfined"

Reference article

https://sott0n.github.io/posts/docker_gdb/

Recommended Posts

Support for gdb errors in Docker containers
Show Better Errors in Rails + Docker environment
Commands that helped resolve errors in Docker
Dealing with composer installation errors in Docker
[Rails5.2] Support for emoji of Mysql 5.7 in Docker (change character code to utf8mb4)
Docker in LXD
Support out of support in docker environment using centos6
Information about workarounds for Carthage build errors in Xcode 12
About Java 10 Docker support
Configuration script for using docker in proxy environment on ubuntu 20.04.1