Linux/Ubuntu Server

[docker] gdb(ptrace) in docker container

gdb는 강력한 CUI debugging 툴이다.

그리고 gdb는 ptrace의 집합체이다.

ptrace는 privilege가 많이 필요하다. 

리눅스를 별로 안좋아해서 관련된 지식은 잘 모르겠다.


docker는 container를 안전한 환경을 위해...?

apparmor 나 privilege를 설정한다.


그래서 ptrace가 작동되지 않는다. 

실제로 ptrace의 반환값이 -1이다. errno를 보면 permission denied겠지.


그걸 해결하려면 container 자체의 권한을 바꾸어주어야 한다.

container가 이미 만들어진 뒤에 권한 바꾸는 것은

내가 하진 않았는데 아마 으 어딘지 까먹었는데 capabilities 설정하는데가있다. 

파일하나에 여러가지 cap들을 명시해놓는데 거기에 추가하면 된다.


container를 새로 만들면서 권한 설정은

--cap-add 로 할 수 있으니 이렇게 만들면 되겠다.


docker run -i -t --name <별명> --cap-add SYS_PTRACE --security-opt apparmor:unconfined <이미지이름>


확인법은.

/proc/1/environ 을 cat해보면 denied가 안뜰것이다.


-------------------------------- for you who wanna read in english~~~ ----------------------


GDB is powerful CUI debugging tool. yeah that's right and gdb is just a collection of ptrace().

Besides ptrace() needs a lot of privilege and I dunno which one it needs.

However docker system doesn't grant its containers particular privileges because of its security .. maybe?

and there's another one "apparmor". I dunno either apparmor or privilege .. I need study Linux more.. :(


Okay. So here we are. All that we need to execute gdb in container is specifying apparmor and privilege to container.

You can allow them when the container has been already created. yes you can but I forgot sory. google it :)


If you are going to create new container then use below command. It sets cap and apparmor which are related with running GDB.


docker run -i -t --name <container alias> --cap-add SYS_PTRACE --security-opt apparmor:unconfined <image name>


To confirm it works command following one.

cat /proc/1/environ


If no error then setting for running gdb is done.

'Linux > Ubuntu Server' 카테고리의 다른 글

[docker] container internet 연결 끊기  (0) 2015.09.20
[docker] file 주고받기  (0) 2015.09.20
[docker] image rename 이름 바꾸기  (0) 2015.09.20
[docker] docker update  (0) 2015.09.20
여러가지 ipconfig 기본 활용법  (0) 2015.09.18
,

알림

이 블로그는 구글에서 제공한 크롬에 최적화 되어있고, 네이버에서 제공한 나눔글꼴이 적용되어 있습니다.

카운터

Today :
Yesterday :
Total :

태그