Golang is an awesome language for web development, but one annoying thing that I hear lots of people complain about is recompiling. Especially when using Docker it can be particularly frustrating. Here and there I hear about different ways of auto-reloading but I haven’t found many posts walking through the steps to set up auto-reloading a Golang project in Docker.

What program?

After spending quite a bit of time trying out and comparing different solutions for auto-reloading I found that CompileDaemon was the best solution for a couple reasons.

  1. The project works as intended
  2. It is simple to use
  3. Doesn’t require any hooks in the code

How to make it work in Docker

Below I have a very basic example of how to setup an auto-reloading project. There are two important options which are required.

  • -build – the build process to build the project.
  • -command – the command to run the project.

In this project below uses a normal build process, so just go build -o app . and because the project is Golang the command is just the executable.

FROM golang:1.11-alpine

RUN apk add --no-cache ca-certificates git

RUN go get github.com/githubnemo/CompileDaemon


COPY . .

CMD CompileDaemon -build="go build -o app ." -command="/www/app"

Most Dockerfiles which are used in the real world are more complicated then this but the general idea works. Although this tutorial is for Golang, this can be used in any language!

Leave a Reply

Your email address will not be published. Required fields are marked *