Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker Autoreload with CompileDaemon

Tags:

docker

go

I am working on trying to improve my development environment using Docker and Go but I am struggling to get auto reloading in my containers working when there is a file change. I am on Windows running Docker Desktop version 18.09.1 if that matters.

I am using CompileDaemon for reloading and my DockerFile is defined as follows

FROM golang:1.11-alpine
RUN apk add --no-cache ca-certificates git
RUN go get github.com/githubnemo/CompileDaemon
WORKDIR /go/src/github.com/testrepo/app
COPY . .
EXPOSE 8080

ENTRYPOINT CompileDaemon -log-prefix=false -directory="." -build="go build /go/src/github.com/testrepo/app/cmd/api/main.go" -command="/go/src/github.com/testrepo/app/main" 

My project structure follows

  • app
    • api
      • main.go

In my docker-compose file I have the correct volumes set and the files are being updated in my container on when I make changes locally.

The application is also started correctly using CompileDaemon on its first load, its just not ever updated on file changes.

On first load I see...

Running build command!
Build ok.
Restarting the given command.

Then any changes I make are not resulting in a restart even though I can connect to the container and see that the changes are reflected in the expected files.

like image 951
dev53 Avatar asked Jul 13 '26 01:07

dev53


1 Answers

Ensure that you have volumes mounted for the services you are using, it is what makes the hot reloading work inside of a Docker container

See the full explanation

like image 79
Steven Victor Avatar answered Jul 15 '26 14:07

Steven Victor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!