Skip to content

Instantly share code, notes, and snippets.

@rpereira
Last active April 7, 2024 14:43
Show Gist options
  • Save rpereira/c52190d18bc41f2ec016c3f15b059e5f to your computer and use it in GitHub Desktop.
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()
}
@whoisstan
Copy link

for Go 1.17+ instead of go get, otherwise you get command not found for CompileDaemon

RUN go get github.com/githubnemo/CompileDaemon

use go install which is the preferred way to install executable commands without changing module dependencies

RUN go install -mod=mod github.com/githubnemo/CompileDaemon

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