Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gdb in docker container returns "ptrace: Operation not permitted."

I've checked /proc/sys/kernel/yama/ptrace_scope in the container and on the host - both report the value as zero but when attached to pid one gdb reports

Reading symbols from /opt/my-web-proxy/bin/my-web-proxy...done. Attaching to program: /opt/my-web-proxy/bin/my-web-proxy, process 1 ptrace: Operation not permitted. 

I've also tried attached to the container with the privileged flag

docker exec --privileged -it mywebproxy_my-proxy_1 /bin/bash 

Host OS is Fedora 25 with docker from their repos and container is a official centos6.8

like image 657
Adrian Cornish Avatar asked Feb 03 '17 17:02

Adrian Cornish


People also ask

How do I enable Ptrace?

Disabling ptrace in docker If you run docker version lower than 19.03 or have kernel version lower than 4.8, ptrace is disabled by default. You can enable it by adding –cap-add=SYS_PTRACE flag. For example {docker run –cap-add=SYS_PTRACE python}. Docker uses seccomp configuration to prevent ptrace from running.

Which of the following is an appropriate command for defining and running multi container docker applications?

Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application's services. Then, with a single command, you create and start all the services from your configuration.

Which docker run flag should you use to configure the restart policy for a container?

Using the --restart flag on Docker run you can specify a restart policy for how a container should or should not be restarted on exit.

Which docker run flag lifts Cgroup limitations?

The --privileged flag gives all capabilities to the container, and it also lifts all the limitations enforced by the device cgroup controller. In other words, the container can then do almost everything that the host can do.


1 Answers

I discovered the answer - the container needs to be started with strace capabilities

Adding this to my docker-compose.yml file allows GDB to work

cap_add:     - SYS_PTRACE 

Or it can also be passed on the docker command line with --cap-add=SYS_PTRACE

like image 119
Adrian Cornish Avatar answered Oct 07 '22 20:10

Adrian Cornish