Skip to content

Instantly share code, notes, and snippets.

@rpereira
Last active March 14, 2024 09:50
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save rpereira/c52190d18bc41f2ec016c3f15b059e5f to your computer and use it in GitHub Desktop.
Setup Docker for Go development with hot reload
---
version: "3.7"
services:
app:
build: .
image: hot-reloading-app
ports:
- "8080:8080" # Web Server
volumes:
- ./:/app
environment:
PORT: "8080"
FROM golang:latest
RUN mkdir /app
WORKDIR /app
ADD . /app
RUN go get github.com/githubnemo/CompileDaemon
RUN go get github.com/gin-gonic/gin
ENTRYPOINT CompileDaemon --build="go build main.go" --command=./main
package main
import "github.com/gin-gonic/gin"
func setupRouter() *gin.Engine {
r := gin.Default()
r.GET("/ping", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "pong",
})
})
return r
}
func main() {
r := setupRouter()
// listen and serve on 0.0.0.0:8080
r.Run()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment