Skip to content

Instantly share code, notes, and snippets.

@wsgac
Created May 14, 2019 15:47
Show Gist options
  • Select an option

  • Save wsgac/74afd75461efd52b031ca95fed6f525b to your computer and use it in GitHub Desktop.

Select an option

Save wsgac/74afd75461efd52b031ca95fed6f525b to your computer and use it in GitHub Desktop.
Basic setup for VSCode debugging of a Dockerized Go application with Delve
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"
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"]
{
// 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": []
}
]
}
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))
}
@wsgac
Copy link
Copy Markdown
Author

wsgac commented May 14, 2019

This assumes that the project lives in a directory also named tutorial.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment