我已经尝试了所有方法都没有解决我的热重载问题,容器会正常加载并构建代码,但是修改代码后代码会改变,但空气包不会做任何事情重建。
Dockerfile:
FROM golang:alpine
ENV GO111MODULE=on
EXPOSE 8080
RUN mkdir /app
WORKDIR /app
COPY go.mod .
COPY go.sum .
RUN go mod download
RUN go get github.com/cosmtrek/air
COPY . .
ENTRYPOINT ["air", "-c", ".air.toml"]
docker-compose.yml
go:
container_name: go
build:
dockerfile: Dockerfile
context: ./
volumes:
- ./:/app
ports:
- '8080:8080'
.air.toml
root = "."
testdata_dir = "testdata"
tmp_dir = "tmp"
[build]
bin = "./tmp/main"
cmd = "go build -o ./tmp/main ."
delay = 1000
exclude_dir = ["assets", "tmp", "vendor", "testdata"]
exclude_file = []
exclude_regex = ["_test.go"]
exclude_unchanged = false
follow_symlink = false
full_bin = ""
include_dir = []
include_ext = ["go", "tpl", "tmpl", "html"]
kill_delay = "0s"
log = "build-errors.log"
send_interrupt = false
stop_on_error = true
[color]
app = ""
build = "yellow"
main = "magenta"
runner = "green"
watcher = "cyan"
[log]
time = false
[misc]
clean_on_exit = false
[screen]
clear_on_rebuild = false