Pro tip: If you don’t want to alter your original Docker container or the Run Configuration used for it, then you can create a duplicate Dockerfile and a duplicate Run Configuration. This allows us to run a debugger inside the container at the cost of some security features, so it should only be used on debugging containers, but not production ones. `–security-opt=”apparmor=unconfined” –cap-add=SYS_PTRACE` In the Command line options section of the Docker container Run Configuration, we need to add the following value: Changing the Run Configuration to allow the debugger to runīefore we start the debugging session, we also need to change how the container runs. And finally, we’ll add both Delve and our binary to the image. We also need to compile the application with special flags to enable a better debugging experience that results from turning off optimizations from the compiler. These changes add Delve, the Go debugger, to the container image and instruct the container to start the application via Delve. RUN go build -gcflags='all=-N -l' -o /serverĬMD Using the same repository that we used in the last article, we can switch our branch to the debug branch.įirst, we’ll need to make a few changes to our Dockerfile.
Today, we’ll take a look at how to debug a Go application that runs inside a container. In the previous article of this series, we discussed how to get started using Docker to run our Go applications.