# How to debug an app in a contaier
To debug an application running it inside a docker container, you have to include a new configuration block in VSCode. Go to debug area and press 'Add Configuration'.
You also need to have some elements previously installed/configured:
Inside the docker container, you need to have:
- gdb installed.
- all the binaries of your app compilled with debug symbols (_-g_)
- Run the docker container with the entrypoint set as: _/bin/bash_
In your local machine:
- VSCode installed
- C++ and Gdb VSCode extensions installed (c/c++ , cmake, cmake tools, Native Debug)
- The application code folder oppened (in VSCode) choosing the root folder (main CMakeLists.txt file location)
- Run docker with these parameters:
* alias docker='sudo docker'
* sudo code --user-data-dir="~/.vscode-root" // Run VSCode as root
Here, you have to add a new debug configuration inside the launch.json script. You can open this script from "Debug->Add Configuration...". Use any of the default templates as reference.
This is an example configuration block to cross debuging the app:
```
...
"version": "0.2.0",
"configurations": [
{
"name": "C++ Docker Launch",
"type": "cppdbg",
"request": "launch",
"program": "hello", // binary name inside docker container
"args": [""],
"stopAtEntry": false,
"cwd": "/data/build", // path to the binary file inside docker container
"environment": [{"CUDA_VISIBLE_DEVICES":"2"}], // List of extra environment variables
"externalConsole": false,
"logging": {
"moduleLoad": true,
"trace": true,
"engineLogging": true
},
"pipeTransport": {
"pipeCwd": "/usr/bin/", // Local directory of pipe program (docker)
"pipeProgram": "docker", // Pipe program
"pipeArgs": [ "exec","-i", "89739f30ca79", "/bin/bash","-c"], // 89739f30ca79 container id ('-c' concatenates all the app name and the debugger path in the proper way)
"debuggerPath": "/usr/bin/gdb" // Debugger location on the remote machine
//"debuggerArgs": "handle SIGILL nostop"
},
"sourceFileMap": {
"/data/src":"/home/user/app/src" // map remote src with local srcs
}
}
...
```
**WARNING**: Some implementations have problems to be debugged inside the container. In those cases, add the flag "--cap-add=SYS_PTRACE" to the docker container run call.
**WARNING**: In some cases, you need to add _gosu_ call to the launching pipe parameters. In those cases, add _gosu_ and _user_ in pipeArgs list:
"pipeArgs": [ "exec","-i", "89739f30ca79", "gosu" , "user", "/bin/bash","-c"],