Use the air tool inside your Docker container to watch for file changes and automatically rebuild your Go application.
- Install the
airbinary in your container by runninggo install github.com/cosmtrek/air@latest. - Create a
.air.tomlconfiguration file in your project root to define the build command and watch paths. - Run the
aircommand inside your container to start the hot reload loop.
[build]
cmd = "go build -o ./tmp/main ."
bin = "./tmp/main"
include_ext = ["go", "tpl", "tmpl", "html"]
exclude_dir = ["assets", "tmp", "vendor", "testdata"]
docker run -v $(pwd):/app -w /app golang:1.21 air