Start server: docker-compose up
This project first appeared on a blog post I wrote: https://rpereira.pt/programming/setup-docker-for-go-development/
Start server: docker-compose up
This project first appeared on a blog post I wrote: https://rpereira.pt/programming/setup-docker-for-go-development/
| --- | |
| 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() | |
| } |
for Go 1.17+ instead of
go get, otherwise you get command not found for CompileDaemonRUN go get github.com/githubnemo/CompileDaemon
use
go installwhich is the preferred way to install executable commands without changing module dependenciesRUN go install -mod=mod github.com/githubnemo/CompileDaemon