{"id":17025454,"url":"https://github.com/jackyzha0/go-remote-debug","last_synced_at":"2026-05-09T17:43:19.675Z","repository":{"id":103521626,"uuid":"202238387","full_name":"jackyzha0/go-remote-debug","owner":"jackyzha0","description":"A quick tutorial on debugging containerized Go applications!","archived":false,"fork":false,"pushed_at":"2019-08-13T23:43:37.000Z","size":641,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-27T23:17:12.920Z","etag":null,"topics":["debugging","delve","docker","go"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jackyzha0.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-08-13T23:35:49.000Z","updated_at":"2024-05-08T06:11:26.000Z","dependencies_parsed_at":null,"dependency_job_id":"5f22a4e5-6d5a-46b9-aedc-a39dfc54f566","html_url":"https://github.com/jackyzha0/go-remote-debug","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jackyzha0%2Fgo-remote-debug","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jackyzha0%2Fgo-remote-debug/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jackyzha0%2Fgo-remote-debug/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jackyzha0%2Fgo-remote-debug/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jackyzha0","download_url":"https://codeload.github.com/jackyzha0/go-remote-debug/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245007238,"owners_count":20546142,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["debugging","delve","docker","go"],"created_at":"2024-10-14T07:29:12.245Z","updated_at":"2026-05-09T17:43:14.642Z","avatar_url":"https://github.com/jackyzha0.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Remote Debugging Containerized Go Applications\n#### A guide by Jacky Zhao\n\nBelow is a quick, basic tutorial on how to use IntelliJ's Go plugin (or GoLand) to debug\nGo applications running in Docker containers. To do this, we build the containers\nwith a tool called Delve, the Go debugger.\n\n## 0. Pre-requisites\n\nBefore we start, ensure that you have both the Go and Docker Integration plugins installed.\n`Settings \u003e Plugins \u003e Install JetBrains Plugin \u003e Docker integration` \u003cbr\u003e\n`Settings \u003e Plugins \u003e Install JetBrains Plugin \u003e Go`\n\n## 1. Create the app.\n\nFor this tutorial, we will be using this basic Go 'Hello World' program as our 'app.'\n\u003cb\u003e PLEASE make sure this project is created under a VALID GOPATH! \u003cbr\u003ee.g. `~/go/src/go-remote-debug-tutorial/example-app/app.go`\u003c/b\u003e\n\n```go\npackage main\n\nimport (\n\t\"net/http\"\n)\n\nfunc response(w http.ResponseWriter, r *http.Request) {\n\tw.Write([]byte(`Hello world`))\n}\n\nfunc main() {\n\thttp.HandleFunc(\"/\", response)\n\n\tif err := http.ListenAndServe(\":8080\", nil); err != nil {\n\t\tpanic(err)\n\t}\n}\n```\n\n## 2. Create the dockerfile\n\nCreate a file called `Dockerfile-app` under the `example-app` directory\nwith the following contents.\n\n```dockerfile\n## Create Builder Container\nFROM golang:1.12.0-alpine3.9 as builder\nENV CGO_ENABLED 0\n\n# Make sure this path mirrors what you have in $GOPATH\nADD . /go/src/go-remote-debug-tutorial/example-app/\n\n# Install requirements for the app\nRUN apk add --no-cache git\n\n# Compile the app WITHOUT optimization flags, allows Delve to\n# provide a better debug experience. This creates an executable `server`\n# and looks under `go-remote-debug-tutorial/example-app` for the Go files.\nRUN go build -gcflags \"all=-N -l\" -o /server go-remote-debug-tutorial/example-app\n\n# Install Delve\nRUN go get github.com/derekparker/delve/cmd/dlv\n\n## Create Instance Container, we use Alpine to reduce size\nFROM alpine:3.7\n \n# Allow delve to run on Alpine based containers.\nRUN apk add --no-cache libc6-compat\n\n# Expose debug port and application port\nEXPOSE 40000 8080\n\n# Set current working directory\nWORKDIR /\n\n# Copy the compiled executable to root\nCOPY --from=builder /server /\n# Copy the delve executable to root\nCOPY --from=builder /go/bin/dlv /\n\n# Run Delve on port 40000 on \nCMD /dlv --listen=:40000 --headless=true --api-version=2 --accept-multiclient exec ./server\n```\n\nTo make it easier to scale this for larger applications where there may be\nmultiple services that need to be running at once, we create a `docker-compose.yaml`\nunder the root directory.\n\n```dockerfile\nversion: \"3.7\"\nservices:\n  example-app:\n    build:\n      context: ./example-app\n      dockerfile: Dockerfile-app\n    expose:\n      - \"8080\"\n      - \"40000\"\n    ports:\n      - \"40000:40000\"\n      - \"8080:8080\"\n    security_opt:\n      - \"apparmor:unconfined\"\n    cap_add:\n      - \"SYS_PTRACE\"\n```\n\n## 3. Creating the run configuration\n\nConveniently, IntelliJ has something called `Run Configurations` which allow us to run all of our docker images\nfrom within the IDE. Here's how to set it up and use it.\n\n1. First, we want to edit our `Run/Debug Configurations`. Click on Add Configuration. \u003cbr\u003e\u003cbr\u003e\n![1](image_src/1.png) \u003cbr\u003e\u003cbr\u003e\n2. Then we want to add a new configuration of Docker Compose under `+ \u003e Docker \u003e Docker-compose`. These run configs \nallow us to start the container quickly through IntelliJ.\u003cbr\u003e\u003cbr\u003e\n![2](image_src/2.png) \u003cbr\u003e\u003cbr\u003e\n3. Fill in the details as follows. Select the `docker-compose.yaml` file for the field `Compose File(s)`. Add \nservices as needed. Under services, add the name of your service (as defined in your `docker-compose.yaml`), in this case: `example-app`.\u003cbr\u003e\u003cbr\u003e\n![3](image_src/3.png) \u003cbr\u003e\u003cbr\u003e\n4. Now, we can run all the containers at once with this `Run Config`. \u003cbr\u003e\u003cbr\u003e\n![4](image_src/4.png) \u003cbr\u003e\u003cbr\u003e\n5. Voila! You should see Delve listening on port `40000` with this debug message: `API server listening at: [::]:40000\n` \u003cbr\u003e\u003cbr\u003e\n![5](image_src/5.png) \u003cbr\u003e\u003cbr\u003e\n\nNote: At this point, you should NOT be able to hit the endpoint via curl or Postman because we haven't started IntelliJ's debugger yet.\n\n## 4. Debugging the application\n\n1. Next, we need to add a new configuration for Go Remote under `+ \u003e Go Remote`. This lets us debug our\ncontainerized Go application through IntelliJ.\u003cbr\u003e\u003cbr\u003e\n![6](image_src/6.png) \u003cbr\u003e\u003cbr\u003e\n2. Set it up as follows. The default port we normally use for Delve is `40000` \u003cbr\u003e\u003cbr\u003e\n![7](image_src/7.png) \u003cbr\u003e\u003cbr\u003e\n3. We can then connect to the Delve instance in the container by running the `go-remote-debug` \nDebug Configuration that we just made by hitting the red bug. \u003cbr\u003e\u003cbr\u003e\n![8](image_src/8.png) \u003cbr\u003e\u003cbr\u003e\n4. Go ahead and set some breakpoints in `app.go`! Now when you hit the service, it should stop at the \nbreakpoints.\n![9](image_src/9.png) \u003cbr\u003e\u003cbr\u003e\n![10](image_src/10.png) \u003cbr\u003e\u003cbr\u003e\n\nEnjoy remote debugging :)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjackyzha0%2Fgo-remote-debug","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjackyzha0%2Fgo-remote-debug","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjackyzha0%2Fgo-remote-debug/lists"}