Created
May 14, 2019 15:47
-
-
Save wsgac/74afd75461efd52b031ca95fed6f525b to your computer and use it in GitHub Desktop.
Basic setup for VSCode debugging of a Dockerized Go application with Delve
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| version: '2' | |
| services: | |
| tutorial: | |
| build: . | |
| security_opt: | |
| - seccomp:unconfined | |
| entrypoint: dlv debug tutorial -l :40000 --headless=true --api-version=2 --log=true | |
| ports: | |
| - "8080:8080" | |
| - "40000:40000" | |
| expose: | |
| - "8080" | |
| - "40000" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| FROM golang:1.11.10-alpine3.8 | |
| ENV CGO_ENABLED 0 | |
| ENV GOPATH /opt/go:$GOPATH | |
| ENV PATH /opt/go/bin:$PATH | |
| ADD . /opt/go/src/tutorial | |
| WORKDIR /opt/go/src/tutorial | |
| RUN apk add --no-cache git | |
| RUN go get github.com/derekparker/delve/cmd/dlv | |
| RUN go build -o tutorial tutorial.go | |
| CMD ["./tutorial"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| // Use IntelliSense to learn about possible attributes. | |
| // Hover to view descriptions of existing attributes. | |
| // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | |
| "version": "0.2.0", | |
| "configurations": [ | |
| { | |
| "name": "Remote Docker", | |
| "type": "go", | |
| "request": "launch", | |
| "mode": "remote", | |
| "remotePath": "/opt/go/src/tutorial", | |
| "port": 40000, | |
| "host": "172.19.0.2", | |
| "program": "${workspaceRoot}", | |
| "env": {}, | |
| "args": [] | |
| } | |
| ] | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "log" | |
| "net/http" | |
| ) | |
| func main() { | |
| log.Println("Starting server") | |
| http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | |
| log.Printf("Handling request\n") | |
| nr := 1 | |
| msg := `Hello World` | |
| w.Write([]byte(fmt.Sprintf("Message: \"%s\" Number: %d", msg, nr))) | |
| }) | |
| log.Fatal(http.ListenAndServe(":8080", nil)) | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This assumes that the project lives in a directory also named
tutorial.